Hi all
I am new to Django and a bit lost at sea. I want to use Bootstrap and
their accordion control. I have these models:
class Research_Category_Group(models.Model):
name = models.CharField(max_length=40)
class Meta:
ordering = ["name"]
class Research_Category(models.Model):
name = models.CharField(max_length=40)
group = models.ForeignKey(Research_Category_Group)
class Meta:
ordering = ["group","name"]
I want to see something like this (if you can picture it via ascii-art):
----
Bonds
US
Europe
----
Equities
Japan
Germany
----
but I get:
----
Bonds
US
----
Europe
----
Equities
Japan
----
Germany
----
My view is:
def add_document(request):
category_list = Research_Category.objects.all()
return render_to_response("research/add_document.html",
{"category_list": category_list},
context_instance=RequestContext(request))
The template is:
<div class="accordion" id="category_accordion">
<div class="accordion-group">
{% for category in category_list %}
{% ifchanged category.group %}
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse"
data-parent="#category_accordion" href="#{{ category.group }}">
{{ category.group }}
</a>
</div>
<div id="{{ category.group }}" class="accordion-body collapse in">
{% endifchanged %}
<div class="accordion-inner">
<label class="checkbox"> <input type="checkbox"> {{ category.name
}}</label>
</div>
{% ifchanged category.group %}
</div>
{% endifchanged %}
{% endfor %}
</div>
</div>
So I figure I need to have a nested queryset - which I can't figure how
to do. If I managed it I'm not sure I would know how to use it in the
template.
Or, I need to be cleverer in the template, I am using {% ifchanged
category.group %}, but that is not enough to group the things within
each accordion heading, as I don't know how to "delay" that trailing
</div> properly.
Anyone able to help?
--
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+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.