#3746: Add a wildcard object for use in objects.filter queries.
------------------------------------------+---------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Status: new | Component: Database
wrapper
Version: SVN | Resolution:
Keywords: wildcard filter query | Stage: Design
decision needed
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
------------------------------------------+---------------------------------
Changes (by Simon G. <[EMAIL PROTECTED]>):
* needs_better_patch: => 0
* stage: Unreviewed => Design decision needed
* needs_tests: => 0
* needs_docs: => 0
Comment:
Accepted for a Design Decision.
& for readability, here's the code provided by Justin wikified:
{{{
def people_report(request, **kw):
for key in ('name', 'occupation'):
query_params = {}
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) ...
}}}
Proposed patch:
{{{
#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#comment:1>
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
-~----------~----~----~----~------~----~------~--~---