Re: Using a variable for a field name in a filter?
Wouldn't this work?
kwargs = { var_field: "found" }
Foo.objects.filter(**kwargs)
On May 14, 3:19 pm, derek <gamesb...@gmail.com> wrote:
> Given a model Foo, with a field bar:
> Foo.objects.filter(bar = "found")
> works just fine.
>
> But, in my case, different fields are needed at different times, so I
> would like to use:
> Foo.objects.filter(var_field = "found")
> where "var_field" is a variable which will be set to the name of a
> field (such as "bar").
>
> The above is incorrect - how do I accomplish this?
>
> Thanks
> Derek
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home