0

I think example is worth more than words.

I want to rewrite this :

person = Person.objects.filter(email__contains="gmail.com")

somehow like this :

condition = "email__contains"
person = Person.objects.filter(condition="gmail.com")

Is this possible ?

trinchet
  • 6,753
  • 4
  • 37
  • 60
Kubber
  • 367
  • 3
  • 13
  • do you mean `email_contains` or `email__contains`? it is inconsistently spelled in your example - or is it on purpose? – janbrohl Jul 29 '16 at 16:04

1 Answers1

3

Independently of django you could call

condition = "email__contains"
person = Person.objects.filter(**{condition:"gmail.com"})

instead of

person = Person.objects.filter(email__contains="gmail.com")

because func(kw=arg) means the same as func(**{"kw":arg})

janbrohl
  • 2,626
  • 1
  • 17
  • 15