I have two models:
Rubric(models.Model):
name = models.CharField()
Magazine(models.Model):
name = models.CharField()
rubrics = models.ManyToManyField(
Rubric, related_name="magazines", )
When I try to access all rubric names for my magazines, I have None names
>>> names = [i.rubrics.name for i in Magazine.objects.all()]
>>> [None, None..]
What I do wrong, help me understand this, please
I found a solution. When I call MtM field rubrics, I call manager for Rubric model, so I need to use the manager's method.
[i.rubrics.all() for i in News.objects.all()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With