From 050351c339fae5f0b497875a831c35d07f338cd1 Mon Sep 17 00:00:00 2001 From: Robert Wittams Date: Tue, 20 Dec 2005 22:17:25 +0000 Subject: [PATCH] magic-removal: removed circular reference from options to model class git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1748 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/base.py | 3 ++- django/db/models/options.py | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 47aea38cf0..63d1c490fc 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -20,6 +20,7 @@ if not hasattr(__builtins__, 'set'): from sets import Set as set attribute_transforms = {} + class ModelBase(type): "Metaclass for all models" def __new__(cls, name, bases, attrs): @@ -119,7 +120,7 @@ class Model(object): def _prepare(cls): # Creates some methods once self._meta has been populated. opts = cls._meta - opts._prepare() + opts._prepare(cls) if opts.order_with_respect_to: cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True) diff --git a/django/db/models/options.py b/django/db/models/options.py index 00dd412dea..cdab02e88d 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -45,8 +45,6 @@ class Options: raise TypeError, "'class META' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()) def contribute_to_class(self, cls, name): - # TODO: Remove this self.model reference. This is a circular reference. - self.model = cls cls._meta = self self.object_name = cls.__name__ self.module_name = get_module_name(self.object_name ) @@ -58,7 +56,7 @@ class Options: self.merge_meta() del self.meta - def _prepare(self): + def _prepare(self, model): if self.order_with_respect_to: self.order_with_respect_to = self.get_field(self.order_with_respect_to) self.ordering = ('_order',) @@ -82,7 +80,7 @@ class Options: if self.pk is None: auto = AutoField(verbose_name='ID', primary_key=True) auto.creation_counter = -1 - self.model.add_to_class('id', auto) + model.add_to_class('id', auto) self.pk = self.fields[0] # Cache whether this has an AutoField. self.has_auto_field = False