A lot of times I find myself filtering for an object and returning None
if it can't be found. However, the method I do this seems really inefficient (in terms of lines of code)
When I filter for an object I normally do something like this:
person = Person.objects.filter(id=id)
if person:
person = Person.objects.get(id=id)
else:
person = None
Is there a better way of doing this?
Edit I have made edits to clarify confusion on my end. The filter query should always return 1 object, if it exists.