Django: show a ManyToManyField in a template?

后端 未结 3 1826
别跟我提以往
别跟我提以往 2020-12-01 01:23

I\'ve got these models in my Django project:

class Area(models.Model):
    name = models.CharField(max_length=100, primary_key=True)
    def __unicode__(self         


        
3条回答
  •  不思量自难忘°
    2020-12-01 02:04

    Use place.area.all in the template
    http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

    {% for place in places %}
        Name: {{ place.name }}
    Area:
    {% for area in place.area.all %}{{ area }}
    {% endfor %} {% endfor %}

提交回复
热议问题