From 919df8b8c7b268105260a8d08d4308dc3cd34a25 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 26 Jun 2006 16:20:58 +0000 Subject: [PATCH] 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 --- django/db/models/base.py | 8 ++++++-- django/db/models/loading.py | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index de42a5790b..73abd018ff 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -9,7 +9,7 @@ from django.db.models.query import orderlist2sql, delete_objects from django.db.models.options import Options, AdminOptions from django.db import connection, backend, transaction 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.utils.datastructures import SortedDict from django.utils.functional import curry @@ -60,7 +60,11 @@ class ModelBase(type): new_class._prepare() 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): __metaclass__ = ModelBase diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 56e7d55652..10ff3bb8d8 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -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 None if no model is found. """ - get_apps() # Run get_apps() to populate the _app_list cache. Slightly hackish. try: model_dict = _app_models[app_label] except KeyError: