Let’s say that I have a blog entry with multiple tags. The tags field is a ManyToMany in my model. I want to take all blog entries and for each entry I want to get all tags.
Basically I would do something like that
entries = Entries.objects.get(author=user)
for entry in entries:
tags[entry.pk] = entry.tags.all()
The problem is that I get the MultipleObjectsReturned error.
If you want to return all entries with
author=user, then usefilter()At the moment, you are using
get(), which expects to return oneEntriesobject. As there is more that oneEntrieswithauthor=user, you get theEntries.MultipleObjectsReturnederror.Note, with Django, the convention is to use the singular name
Entryfor your model, instead of the pluralEntries.