Author: mtredinnick
Date: 2008-08-28 21:40:50 -0500 (Thu, 28 Aug 2008)
New Revision: 8690

Modified:
   django/trunk/django/db/models/fields/related.py
Log:
Fixed #7823 -- Fixed an edge case in RelatedField.get_db_prep_lookup() so that
it works correctly with custom field subclasses. Patch from Ivan Sagalaev.


Modified: django/trunk/django/db/models/fields/related.py
===================================================================
--- django/trunk/django/db/models/fields/related.py     2008-08-29 01:44:15 UTC 
(rev 8689)
+++ django/trunk/django/db/models/fields/related.py     2008-08-29 02:40:50 UTC 
(rev 8690)
@@ -125,12 +125,18 @@
             # that object. In certain conditions (especially one-to-one 
relations),
             # the primary key may itself be an object - so we need to keep 
drilling
             # down until we hit a value that can be used for a comparison.
-            v = value
+            v, field = value, None
             try:
                 while True:
-                    v = getattr(v, v._meta.pk.name)
+                    v, field = getattr(v, v._meta.pk.name), v._meta.pk
             except AttributeError:
                 pass
+            if field:
+                if lookup_type in ('range', 'in'):
+                    v = [v]
+                v = field.get_db_prep_lookup(lookup_type, v)
+                if isinstance(v, list):
+                    v = v[0]
             return v
 
         if hasattr(value, 'as_sql'):
@@ -138,7 +144,7 @@
             return QueryWrapper(('(%s)' % sql), params)
         if lookup_type == 'exact':
             return [pk_trace(value)]
-        if lookup_type == 'in':
+        if lookup_type in ('range', 'in'):
             return [pk_trace(v) for v in value]
         elif lookup_type == 'isnull':
             return []


--~--~---------~--~----~------------~-------~--~----~
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