Ticket #7823: 7823.2.diff
File 7823.2.diff, 1.4 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/related.py
125 125 # that object. In certain conditions (especially one-to-one relations), 126 126 # the primary key may itself be an object - so we need to keep drilling 127 127 # down until we hit a value that can be used for a comparison. 128 v = value128 v, field = value, None 129 129 try: 130 130 while True: 131 v = getattr(v, v._meta.pk.name)131 v, field = getattr(v, v._meta.pk.name), v._meta.pk 132 132 except AttributeError: 133 133 pass 134 if field: 135 if lookup_type in ('range', 'in'): 136 v = [v] 137 v = field.get_db_prep_lookup(lookup_type, v) 138 if isinstance(v, list): 139 v = v[0] 134 140 return v 135 141 136 142 if hasattr(value, 'as_sql'): … … 138 144 return QueryWrapper(('(%s)' % sql), params) 139 145 if lookup_type == 'exact': 140 146 return [pk_trace(value)] 141 if lookup_type == 'in':147 if lookup_type in ('range', 'in'): 142 148 return [pk_trace(v) for v in value] 143 149 elif lookup_type == 'isnull': 144 150 return []