I’m a django noob, I’ve got a django project with a model setup like:
class community(models.Model):
DIRECTION_CHOICES = (
(u'N', u'North'),
(u'S', u'South'),
(u'E', u'East'),
(u'W', u'West'),
(u'C', u'City'),
)
name = models.CharField(max_length=100)
direction = models.CharField(max_length = 1, choices=DIRECTION_CHOICES)
def __unicode__(self):
return self.name
class Meta:
verbose_name = "Community"
verbose_name_plural = "Communities"
I’d like to add a template page that just displays links to choices as a drill-down type menu like:
***Communities***
* North
* South
* East
* West
* City
and when you click on one you see a list of communities in that area.
Is there a way I can do
{% for area in choices %}
{{ area.name }}
{% endfor %}
??
How about you add this into a form class and display the choices, like this:
https://docs.djangoproject.com/en/dev/ref/forms/fields/#choicefield
Or, you can return the choices in your view, like this:
and in your template: