Accessing tuple element in templatetag, / Generating multi-level lists.

61 views
Skip to first unread message

Petey

unread,
Sep 10, 2011, 3:49:50 PM9/10/11
to django...@googlegroups.com

In my model I use: choices=CATEGORY_CHOICES property.

CATEGORY_CHOICES = (
                        ('hw', "Hardware"),
                        ('soft', "Software"),
                        ('snd', 'Audio'),
                        )
In templatetags it looks like this:
 {%for c in category %}
            {{ c.category|title}}
                        <br>
        {%endfor%}
It always generates ''hw', 'soft' etc instead of Hardware, Software. I have no clue how to access "full-name" for my choices.


2. My second problem is that I dont really understand how I can generate multi-level lists.
{{ c.category }}
 - {{ c.subcategory }}
Could someone explain how the loops should look like?

/// Petey

galgal

unread,
Sep 10, 2011, 4:04:43 PM9/10/11
to django...@googlegroups.com
maybe try:
 {%for c in category.elements %}

uidless

unread,
Sep 10, 2011, 4:06:07 PM9/10/11
to django...@googlegroups.com
Try this one for 1 question: {{object.get_FIELDNAME_display}} - for you it will be look like this {{ c.get_category_display }}

galgal

unread,
Sep 10, 2011, 4:06:49 PM9/10/11
to django...@googlegroups.com

Petey

unread,
Sep 11, 2011, 12:34:47 AM9/11/11
to django...@googlegroups.com
Thanks for your responses.

How I can generate multilevel lists based on fields:
category
 - subcategory


Reply all
Reply to author
Forward
0 new messages