Re: Filter (AND excluding empty values)

2014-08-21 Thread Osiaq
Just to say "thank you" again after 5 years :D But again it saves my ass :D On Wednesday, December 16, 2009 7:17:07 AM UTC+2, Phui Hock wrote: > > I see. I think this is probably you are looking for: > > params = ['city', 'category', 'status'] > kwargs = dict([(p, request.GET.get(p)) for p in

Re: Filter (AND excluding empty values)

2009-12-16 Thread Osiaq
@Phui Hock: YES YES YES !!! You are the One, thank you !!! @creecode: Thank you for exclude(**kwargs) manual, will have closer look at it, sounds interesting. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Filter (AND excluding empty values)

2009-12-15 Thread creecode
Hello Osiaq, On Dec 15, 8:40 pm, Osiaq wrote: > Is there anyway to force filter to exclude null values from the > statement? > Logic: "if 'city' is null(or 0), exclude it from search term" ? Did you try the exclude method < http://docs.djangoproject.com/en/dev/ref/models/querysets/#exclude-kwa

Re: Filter (AND excluding empty values)

2009-12-15 Thread Phui Hock
I see. I think this is probably you are looking for: params = ['city', 'category', 'status'] kwargs = dict([(p, request.GET.get(p)) for p in params if request.GET.get(p)]) # use just the request params whose value is not empty string Property.objects.filter(**kwargs) On Dec 16, 12:40 pm, Osiaq w

Re: Filter (AND excluding empty values)

2009-12-15 Thread Osiaq
Well, still the same: VIEW: def search(request): t=request.GET['city'] c=request.GET['category'] s=request.GET['status'] properties =Property.objects.filter(Q(city__isnull=True)|Q(city=t), Q(category__isnull=True) | Q(category=c), Q

Re: Filter (AND excluding empty values)

2009-12-15 Thread Phui Hock
I suppose you can do something like: Property.objects.filter( city=t, Q(category__isnull=True) | Q(category=c), Q (status__isnull=True) | Q(status=s) ) On Dec 16, 9:17 am, Osiaq wrote: > Yes, this one is working properly. > Actually I can use i.e > > properties = Property.objects.filter( Q(city

Re: Filter (AND excluding empty values)

2009-12-15 Thread Osiaq
Yes, this one is working properly. Actually I can use i.e properties = Property.objects.filter( Q(city=t) & Q(category=c ) & Q (status=s) ) These parameters are working perfect for: city='Tokio', category='House', status='For Rent' But fails for: city='Tokio', category null, status null Similar

Re: Filter (AND excluding empty values)

2009-12-15 Thread Alex Robbins
Does it work for one case at a time? Have you tried q = request.GET.get('city') properties = Property.objects.filter(city=q) I would make sure it is working for each variable before combining them together. (Maybe you already have, I don't know.) Alex On Dec 14, 5:32 pm, Osiaq wrote: > Andy, I

Re: Filter (AND excluding empty values)

2009-12-14 Thread Osiaq
Andy, I couldn't manage it. Could you (please) give me some example? It looks like this case is NOT simple at all, googling through multiple websites didn't bring anything even close to required solution. MODEL: class Property(models.Model): name = models.CharField(max_length=200)

Re: Filter (AND excluding empty values)

2009-12-14 Thread Osiaq
Thank you, I'm gonna try this way :) -- 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. Fo

Re: Filter (AND excluding empty values)

2009-12-14 Thread Andy McKay
A filter can take a python dictionary. So all you have to do is: Property.objects.filter(**some_dictionary) All you have to do is populate that dictionary. You can do that by accessing request.get, but the best way is to pass that into a django form. -- Andy McKay, @clearwind Whistle

Re: Filter (AND excluding empty values)

2009-12-14 Thread Osiaq
That post wasn't clear, my bad. Again: t=request.GET['city'] c=request.GET['category'] s=request.GET['status'] properties = Property.objects.filter( Q(city=t) | Q (category=c ) | Q(status=s) ) #example filter On the website I've implemented search engine with 3 li

Re: Filter (AND excluding empty values)

2009-12-13 Thread Andy McKay
On 09-12-13 5:46 PM, Osiaq wrote: > properties = Property.objects.filter( Q(city=t) | Q(category=c ) | Q > (status=s) ) > Goal: > Find all the properties in 'city' no matter of category or status Well you haven't told us what your models look like so we can't really be sure what you mean. I

Filter (AND excluding empty values)

2009-12-13 Thread Osiaq
I'm trying some "simple" stuff and just can't find out the solution: t=request.GET['city'] c=request.GET['category'] s=request.GET['status'] properties = Property.objects.filter( Q(city=t) | Q(category=c ) | Q (status=s) ) Goal: Find all the properties in 'city' no