How to access fields in a customized many-to-many through object in templates

后端 未结 1 615
暗喜
暗喜 2021-01-11 13:34

Consider the following models:

class Person(models.Model):
    name = models.CharField(max_length=128)

class Group(models.Model):
    name = models.CharFiel         


        
相关标签:
1条回答
  • 2021-01-11 13:47

    person.membership_set.all() will give you a list of all Membership instances for a given person. You can use this in regular code as well as in the template.

    for each in person.membership_set.all():
        print each.date_joined
    
    {% for each in person.membership_set.all %}
        {{ each.date_joined }}
    {% endfor %}
    
    0 讨论(0)
提交回复
热议问题