[Django]-How to get a single model object using multiple ORM lookup parameters

69👍

Actually, you can pass multiple lookup parameters in QuerySet’s get() method. So how about?

try:
    employee = Employee.objects.get(age=23, sex='female')
except Employee.DoesNotExist:
    # no employee found
except Employee.MultipleObjectsReturned:
    # what to do if multiple employees have been returned?
👤Haes

Leave a comment