You've already had a couple of approaches suggested here, but I have a
question...

On Wed, 2006-09-20 at 19:18 +0100, Luis P. Mendes wrote:
> Hi,
> 
> I want to let a user of one application to be able to filter results in
> a complex way.
> 
> There are twelve variables, all boolean, that can be used to perform
> these filters.  In PostgreSQL, all data for these variables are thus
> saved  as either True of False.
> 
> There is no difficulty to apply individual filters.  My problem regards
> the combination of a variable number of filters.
> 
> The user is presented with twelve radio boxes.  If he/she chooses to
> filter by var3 and var4, code should be built as, for ex.,
> Animals.objects.filter(var3=True).filter(var4=True)
> or as Animals.objects.filter(var3=True, var4=True)
> In these cases, I want to filter all records where var3 and var4 are
> True, and all other variables are either True or False.
[...]
> Since filter accepts a keyword argument, I also tried to use a
> dictionary as {"var3":True,"var4":False} but with no success.

What did you try here? I would have thought this would work. You build
up the dictionary and then 

        Animals.objects.filter(**param_dict)
        
should do the trick. This would be the same as filter(var3=True,
var4=True) and that has the effect of combining the variables as if they
were "and"-ed together.

Do you get an errror when you do this or does Django create the wrong
query? To have a look at the query, import django.db and examine
django.db.queries[-1]['sql'] right after evaluating the queryset.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to