mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
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
This commit is contained in:
parent
5eddd9612d
commit
050351c339
@ -20,6 +20,7 @@ if not hasattr(__builtins__, 'set'):
|
|||||||
from sets import Set as set
|
from sets import Set as set
|
||||||
|
|
||||||
attribute_transforms = {}
|
attribute_transforms = {}
|
||||||
|
|
||||||
class ModelBase(type):
|
class ModelBase(type):
|
||||||
"Metaclass for all models"
|
"Metaclass for all models"
|
||||||
def __new__(cls, name, bases, attrs):
|
def __new__(cls, name, bases, attrs):
|
||||||
@ -119,7 +120,7 @@ class Model(object):
|
|||||||
def _prepare(cls):
|
def _prepare(cls):
|
||||||
# Creates some methods once self._meta has been populated.
|
# Creates some methods once self._meta has been populated.
|
||||||
opts = cls._meta
|
opts = cls._meta
|
||||||
opts._prepare()
|
opts._prepare(cls)
|
||||||
|
|
||||||
if opts.order_with_respect_to:
|
if opts.order_with_respect_to:
|
||||||
cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
|
cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
|
||||||
|
@ -45,8 +45,6 @@ class Options:
|
|||||||
raise TypeError, "'class META' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
|
raise TypeError, "'class META' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
|
||||||
|
|
||||||
def contribute_to_class(self, cls, name):
|
def contribute_to_class(self, cls, name):
|
||||||
# TODO: Remove this self.model reference. This is a circular reference.
|
|
||||||
self.model = cls
|
|
||||||
cls._meta = self
|
cls._meta = self
|
||||||
self.object_name = cls.__name__
|
self.object_name = cls.__name__
|
||||||
self.module_name = get_module_name(self.object_name )
|
self.module_name = get_module_name(self.object_name )
|
||||||
@ -58,7 +56,7 @@ class Options:
|
|||||||
self.merge_meta()
|
self.merge_meta()
|
||||||
del self.meta
|
del self.meta
|
||||||
|
|
||||||
def _prepare(self):
|
def _prepare(self, model):
|
||||||
if self.order_with_respect_to:
|
if self.order_with_respect_to:
|
||||||
self.order_with_respect_to = self.get_field(self.order_with_respect_to)
|
self.order_with_respect_to = self.get_field(self.order_with_respect_to)
|
||||||
self.ordering = ('_order',)
|
self.ordering = ('_order',)
|
||||||
@ -82,7 +80,7 @@ class Options:
|
|||||||
if self.pk is None:
|
if self.pk is None:
|
||||||
auto = AutoField(verbose_name='ID', primary_key=True)
|
auto = AutoField(verbose_name='ID', primary_key=True)
|
||||||
auto.creation_counter = -1
|
auto.creation_counter = -1
|
||||||
self.model.add_to_class('id', auto)
|
model.add_to_class('id', auto)
|
||||||
self.pk = self.fields[0]
|
self.pk = self.fields[0]
|
||||||
# Cache whether this has an AutoField.
|
# Cache whether this has an AutoField.
|
||||||
self.has_auto_field = False
|
self.has_auto_field = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user