On Jun 12, 10:55 am, truebosko <[EMAIL PROTECTED]> wrote:
> I have a card store and I would like to add 3 options a user can
> search by. Year, Brand, and Card Title
>
> Normally this would be easy but my dilemna here is:
> - All of these are optional, and if they do not search for a certain
> one, the query should ignore that filter entirely and display in full
> (So if none of the filters are active I display ALL cards)
>
> So basically what I am thinking of was:
>
> if request.POST.get('brand'):
> Q(brand=request.POST.get('brand')
>
> if request.POST.get('year'):
> Q(year=request.POST.get('year')
>
> etc.
>
> cards = Card.objects.filter(... Now how do I get those Q objects into
> here ??).order_by('pk')

Try
cards = Card.objects.filter(Q1&Q2)

Alternatively you can use a dictionary and ** magic:
filter = dict(brand=request.POST.get('brand'),
year=request.POST.get('year'))
cards = Card.objects.filter(**filter)
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to