Ticket #7823: 7823.2.experimental.diff

File 7823.2.experimental.diff, 1.2 KB (added by Ivan Sagalaev, 16 years ago)

Same as 7823.2.diff but more elegant and may be less robust?

  • django/db/models/fields/related.py

     
    125125            # that object. In certain conditions (especially one-to-one relations),
    126126            # the primary key may itself be an object - so we need to keep drilling
    127127            # down until we hit a value that can be used for a comparison.
    128             v = value
     128            v, field = value, None
    129129            try:
    130130                while True:
    131                     v = getattr(v, v._meta.pk.name)
     131                    v, field = getattr(v, v._meta.pk.name), v._meta.pk
    132132            except AttributeError:
    133133                pass
     134            if field:
     135                v = field.get_db_prep_lookup('exact', v)[0]
    134136            return v
    135137
    136138        if hasattr(value, 'as_sql'):
     
    138140            return QueryWrapper(('(%s)' % sql), params)
    139141        if lookup_type == 'exact':
    140142            return [pk_trace(value)]
    141         if lookup_type == 'in':
     143        if lookup_type in ('range', 'in'):
    142144            return [pk_trace(v) for v in value]
    143145        elif lookup_type == 'isnull':
    144146            return []
Back to Top