Fixed another path where imports were creating two instances of a model's
class. Refs #1796, #2232. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3212 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d2b952377c
commit
919df8b8c7
|
@ -9,7 +9,7 @@ from django.db.models.query import orderlist2sql, delete_objects
|
||||||
from django.db.models.options import Options, AdminOptions
|
from django.db.models.options import Options, AdminOptions
|
||||||
from django.db import connection, backend, transaction
|
from django.db import connection, backend, transaction
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
from django.db.models.loading import register_models
|
from django.db.models.loading import register_models, get_model
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
|
@ -60,7 +60,11 @@ class ModelBase(type):
|
||||||
new_class._prepare()
|
new_class._prepare()
|
||||||
|
|
||||||
register_models(new_class._meta.app_label, new_class)
|
register_models(new_class._meta.app_label, new_class)
|
||||||
return new_class
|
# Because of the way imports happen (recursively), we may or may not be
|
||||||
|
# the first class for this model to register with the framework. There
|
||||||
|
# should only be one class for each model, so we must always return the
|
||||||
|
# registered version.
|
||||||
|
return get_model(new_class._meta.app_label, name)
|
||||||
|
|
||||||
class Model(object):
|
class Model(object):
|
||||||
__metaclass__ = ModelBase
|
__metaclass__ = ModelBase
|
||||||
|
|
|
@ -73,7 +73,6 @@ def get_model(app_label, model_name):
|
||||||
Returns the model matching the given app_label and case-insensitive model_name.
|
Returns the model matching the given app_label and case-insensitive model_name.
|
||||||
Returns None if no model is found.
|
Returns None if no model is found.
|
||||||
"""
|
"""
|
||||||
get_apps() # Run get_apps() to populate the _app_list cache. Slightly hackish.
|
|
||||||
try:
|
try:
|
||||||
model_dict = _app_models[app_label]
|
model_dict = _app_models[app_label]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
Loading…
Reference in New Issue