get()
returns a single object. If there is no existing object to return, you will receive <class>.DoesNotExist
. If your query returns more than one object, then you will get MultipleObjectsReturned
. You can check here for more details about get() queries.
Similarly, Django will complain if more than one item matches the get() query. In this case, it will raise MultipleObjectsReturned, which again is an attribute of the model class itself.
M2M will return any number of query that it is related to. In this case you can receive zero, one or more items with your query.
In your models you can us following:
for _topic in topic.objects.all():
_topic.learningobjective_set.all()
you can use _set
to execute a select query on M2M. In above case, you will filter all learningObjective
s related to each topic