Reputation: 271644
What is the difference, please explain them in laymen's terms with examples. Thanks!
Upvotes: 22
Views: 9864
Reputation: 2243
I don't know if you really need an example, it's quite easy:
To be more precise:
MyTable.objects.get(id=x).whatever
gives you the whatever
property of your object.get() raises MultipleObjectsReturned if more than one object was found. The MultipleObjectsReturned exception is an attribute of the model class.
get() raises a DoesNotExist exception if an object wasn’t found for the given parameters. This exception is also an attribute of the model class.
MyTable.objects.filter(somecolumn=x)
is not only usable as a list, but you can also query it again, something like MyTable.objects.filter(somecolumn=x).order_by('date')
. for obj in MyTable.objects.filter(somecolumn=x)
Upvotes: 48