Added comments to clarify the string->field name resolution logic.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3196 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2006-06-23 07:43:33 +00:00
parent 0d4b5b9b4a
commit 6cbdbffc80
1 changed files with 3 additions and 0 deletions

View File

@ -23,11 +23,14 @@ def add_lookup(rel_cls, field):
name = field.rel.to name = field.rel.to
module = rel_cls.__module__ module = rel_cls.__module__
key = (module, name) key = (module, name)
# Has the model already been loaded?
# If so, resolve the string reference right away
model = get_model(rel_cls._meta.app_label,field.rel.to) model = get_model(rel_cls._meta.app_label,field.rel.to)
if model: if model:
field.rel.to = model field.rel.to = model
field.do_related_class(model, rel_cls) field.do_related_class(model, rel_cls)
else: else:
# Mark the related field for later lookup
pending_lookups.setdefault(key, []).append((rel_cls, field)) pending_lookups.setdefault(key, []).append((rel_cls, field))
def do_pending_lookups(sender): def do_pending_lookups(sender):