How to join ManyToMany querysets in Django/Python -
for example, have 2 models:
class user(abstractuser): achievement = models.manytomanyfield('achievement') class achievement(models.model): name = models.charfield(max_length=50)
i need achievements of several users, think, should this:
for user in user.objects.filter(bla-bla): achievement_list += user.achievement
but returns error "'manyrelatedmanager' object not iterable"
user.achievement
manyrelatedmanager
, similar how, say, achievement.objects
manager
. try instead user.achievement.all()
or user.achievement.filter(...)
(with whatever filter may want).
Comments
Post a Comment