#12517: Mistake in example for django.db.models.get_prep_lookup()
------------------------------------+---------------------------------------
Reporter: dja...@pressure.net.nz | Owner: nobody
Status: new | Milestone:
Component: Documentation | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------+---------------------------------------
http://docs.djangoproject.com/en/dev/howto/custom-model-
fields/#django.db.models.get_prep_lookup
In the example, the return value for an exact lookup is wrapped in a list:
{{{
#!python
def get_prep_lookup(self, lookup_type, value):
# We only handle 'exact' and 'in'. All others are errors.
if lookup_type == 'exact':
return [self.get_prep_value(value)]
}}}
This then gets passed to the DB connection's compiler in
get_db_prep_lookup, and seeing a list, does a typecast to ARRAY (in the
case of Postgres).
I think the example should in fact return just the value, not wrapped in a
list (also as per the default implementation of get_prep_lookup in the
source):
{{{
#!python
def get_prep_lookup(self, lookup_type, value):
# We only handle 'exact' and 'in'. All others are errors.
if lookup_type == 'exact':
return self.get_prep_value(value)
}}}
By making this change to a custom field I have, the undesired typecast
behaviour described above is avoided.
--
Ticket URL: <http://code.djangoproject.com/ticket/12517>
Django <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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.