Wednesday, July 25, 2012

Re: Variable # of fields in a form

On 2012/07/23 03:08 PM, Alex Strickland wrote:

> https://docs.djangoproject.com/en/dev/topics/forms/formsets/ ?

No.

This is my html that shows a nice looking control using bootstrap, with
lists of users broken up into their groups:

<div class="accordion" id="group_accordion">
{% for group in group_list %}
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse"
data-parent="#group_accordion" href="#{{ group.name }}">
{{ group.name }}
</a>
</div>
<div id="{{ group.name }}" class="accordion-body collapse {% if
forloop.counter0 == 0 %} in{% endif %}">
<div class="accordion-inner">
{% for user in group.user_set.all %}
<label class="checkbox"> <input type="checkbox" name="{{
user.id }}" > {{ user.first_name }} {{ user.last_name }}</label>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</div>

But for the life of me I cannot figure out the "Django" way of achieving
this and leveraging the benefits of something like this:

foo = forms.ModelMultipleChoiceField(
User.objects.all(),
widget=forms.CheckboxSelectMultiple)

I think I'll have to do all the messy data handling myself, but maybe
someone has the answer?

--
Regards
Alex

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment