

def _pk_trace(self, value, prep_func, lookup_type, **kwargs):
    v = value
    if isinstance(v, self.rel.to):
        field_name = getattr(self.rel, 'field_name', None)
    else:
        field_name = None
    try:
        while True:
            if (field_name is None):
                field_name = v._meta.pk.name
            v = getattr(v, field_name)
            field_name = None
    except AttributeError:
        pass
    except exceptions.ObjectDoesNotExist:
        v = None
    field = self
    while field.rel:
        if hasattr(field.rel, 'field_name'):
            field = value.rel.to._meta.get_field(field.rel.field_name)
        else:
            field = field.rel.to._meta.pk
    if (lookup_type in ('range', 'in')):
        v = [v]
    v = getattr(field, prep_func)(lookup_type, v, **kwargs)
    if isinstance(v, list):
        v = v[0]
    return v

dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/models/fields/related.py RelatedField._pk_trace/VarMisuse@149/191 `field`->`value`