When I ask the model manager to get an object, it raises DoesNotExist
when there is no matching object.
go = Content.objects.get(name=\"baby\")
To make things easier, here is a snippet of the code I wrote, based on inputs from the wonderful replies here:
class MyManager(models.Manager):
def get_or_none(self, **kwargs):
try:
return self.get(**kwargs)
except ObjectDoesNotExist:
return None
And then in your model:
class MyModel(models.Model):
objects = MyManager()
That's it. Now you have MyModel.objects.get() as well as MyModel.objetcs.get_or_none()