def _get_field(self, lookup):
'''
Return the Django model field for a lookup plus the remainder of the lookup,
which should be the lookup type.
'''
field = None
lookup_type = None
bits = lookup.split(LOOKUP_SEP)
model = self.model
for i, bit in enumerate(bits):
try:
field = model._meta.get_field(bit)
except FieldDoesNotExist:
lookup_type = LOOKUP_SEP.join(bits[i:])
break
if hasattr(field, 'remote_field'):
rel = getattr(field, 'remote_field', None)
model = getattr(rel, 'model', model)
return field, lookup_type
评论列表
文章目录