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):
return self.name
class Place(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100, primary_key=True)
area = models.ManyToManyField(Area,related_name='area')
How can I show the Place's area name(s) in my template? Currently I have:
{% for place in places %}
Name: {{ place.name }}, Area: {{ place.area}}
{% endfor %}
which gives:
Area: <django.db.models.fields.related.ManyRelatedManager object at 0x10435a3d0>
And {{ place.area}}
is just blank. Can anyone help?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…