user3633756
user3633756

Reputation: 13

dynamic Search? how?

That way or you can do this:

for key, value in data.items():
    instance = model_class.objects(key = value)

or can only be done this way?:

instance = model_class.objects(pk = value)

Upvotes: 1

Views: 88

Answers (1)

alecxe
alecxe

Reputation: 474161

Deliver keyword arguments by unpacking the dictionary:

instance = model_class.objects.filter(**data)

where keys in data dictionary are model_class field names.

Upvotes: 2

Related Questions