Sunday, May 26, 2013

2 Questions: Passing Filter Options to a View & Efficient QuerySet Evaluation

Hello,

So my question is a 2 part question. The first part leads into the second part.

So my first question goes like this. Say I'm on a webpage and I go through about 3 drop down selection filter menu's/options. I then hit submit. My question is how would I pass these arguments to the view that then would take those requested filter values and actually evaluate the database to return the correct objects from the database to a template? Initially, I thought maybe some sort of url generation/parsing/passing would be involved but I really don't know how to create a dynamic interchange here. I really don't think defining a set of standard querysets against in a view to go against a database is the best option. Like for example if I wanted to filter my database by 3 different criteria and each criteria had 4 filters that would be 3 x 4 possiblities and 12 unique view methods/queries I would have to write. Not good by any means.

My second question spans off of the first question. So let's say now I have these criteria (Let's call it 3 specific criteria following the first paragraph's direction) and I want to go ahead and efficiently query the database given the populated queryset I have formed. How can I ensure these queries will be of the utmost efficiency? I need each query by each user on the site to have an extremely low footprint on the sites bandwith/resoures/etc. The reason being: Let's say I have 1,000,000 objects in the database. Say all the entries are geographically related. So maybe points in lat lon across the US. And say I'm filtering by distance off a location. That to me is a heck of a lot of queries that have to be done and surely how I write that has to be really efficient. 

Again on question 2 I would be chaining queries so:

Chaining filters

The result of refining a QuerySet is itself a QuerySet, so it's possible to chain refinements together. For example:

>>> Entry.objects.filter(  ...     headline__startswith='What'  ... ).exclude(  ...     pub_date__gte=datetime.date.today()  ... ).filter(  ...     pub_date__gte=datetime(2005, 1, 30)  ... )

and so one of those queries would indeed by geo related so of this nature:

.objects.filter(point__distance_lte=(pnt, D(km=7)))

and I then I would still break the query down by a few other criteria for example. So any advice on how to make my chained queries extremely efficient would be great!

If I have no given enough information I would be more then happy to dive into more detail on each specific thing. The django community is the best in my opinion so I'm willing to go the extra mile and try to explain myself more for the chance for more great help!

Thanks so much,

JJ Zolper

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate