#3746: Add a wildcard object for use in objects.filter queries.
---------------------------------------+------------------------------------
Reporter:  [EMAIL PROTECTED]  |       Owner:  adrian               
  Status:  new                         |   Component:  Database wrapper     
 Version:  SVN                         |    Keywords:  wildcard filter query
   Stage:  Unreviewed                  |   Has_patch:  0                    
---------------------------------------+------------------------------------
 Advantage:  Greatly simplify a common usage with no breakage of old code,
 while making code more pythonic.
 
 There should be a wildcard object to pass with keyword params to filter(),
 such that any keyword param is ignored which equals this wildcard object.
 This should not break any existing code.
 
 Examples:
 def people_report(request, **kw):
     for key in ('name', 'occupation'):
         query_params = {}
         if if key in kw and kw[key] != None:
             query_params[key] = kw[key]
     people = Person.objects.filter(**query_params)
     ...
 
 #COMPARED TO
 
 def people_report(request, name=WILDCARD, occupation=WILDCARD):
     people = Person.objects.filter(name=name, occupation=occupation)
     ...
 
 
 #Implementation:
 
 change django.db.models.manager.filter from:
 
 def filter(self, *args, **kwargs):
     return self.get_query_set().filter(*args, **kwargs)
 
 TO:
 def filter(self, *args, **kwargs):
     for key in kwargs:
         if kwargs[key] == django.db.models.manager.WILDCARD:
             del kwargs[key]
     return self.get_query_set().filter(*args, **kwargs)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3746>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to