Sorry, didn't initially see the replies, repeating the answer to
Javier and Nuno!

On May 15, 10:09 am, chewynougat <peter_i_campb...@hotmail.co.uk>
wrote:
> Hi Derek,
>
> If I am thinking correctly, you can build up a list of keyword
> arguments in a dictionary for a filter query (or any query).
>
> So, for example, in a for loop:
>
> first time round:
> kwargs = {'foo': 'found'} where the key is the database field and the
> value is the record(s) you are searching for.
>
> Then you can pass these kwargs in like:
> Foo.objects.filter(**kwargs)
>
> Second time round:
> kwargs = {'bar': 'found'} where the key is the database field and the
> value is the record(s) you are searching for.
>
> Then you can pass these kwargs in like:
> Foo.objects.filter(**kwargs)
>
> You can add as many kwargs as you need e.g. {'foo': 'found', 'bar':
> 'not_found', 'monty': True} etc etc
>
> HTH
>
> Pete Campbell
>
> On May 14, 2: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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to