code: def resolve_model(model, fields):
      
      for (f, v) in fields:
          if v is not None:
              try:
                  kwargs = {f: v}
                  obj = model.objects.get(**kwargs)
                  return obj
              except model.DoesNotExist:
                  pass
              except model.MultipleObjectsReturned:
                  pass
      raise model.DoesNotExist()
docs: model: Model class
      fields: List of 2-tuples of the form (field, value) in order of descending priority