Ticket #7823: 7823.diff

File 7823.diff, 994 bytes (added by Ivan Sagalaev, 16 years ago)

Patch

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

     
    134134            # that object. In certain conditions (especially one-to-one relations),
    135135            # the primary key may itself be an object - so we need to keep drilling
    136136            # down until we hit a value that can be used for a comparison.
    137             v = value
     137            v, field = value, None
    138138            try:
    139139                while True:
    140                     v = getattr(v, v._meta.pk.name)
     140                    v, field = getattr(v, v._meta.pk.name), v._meta.pk
    141141            except AttributeError:
    142142                pass
     143            if field:
     144                v = field.get_db_prep_lookup(lookup_type, v)
     145                if isinstance(v, list):
     146                    v = v[0]
    143147            return v
    144148
    145149        if hasattr(value, 'as_sql'):
Back to Top