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 <osiaq.net...@gmail.com> wrote: > 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(status__isnull=True) | Q > (status=s)) > return render_to_response ('website/search_results.html', > {'property': properties, 'city': t}) > > RESULTS: > Returning url:http://127.0.0.1:8000/search/?city=1&category=1&status=1 > works perfect > Returning url:http://127.0.0.1:8000/search/?city=&category=1&status= > doesnt't work at all (removed 1 from city and status) > > 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" ? -- 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.