mirror of
https://github.com/django/django.git
synced 2025-06-11 06:29:13 +00:00
magic-removal: Simplified overengineered 'attribute_transforms' code in django/db/models/base.py
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2018 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1eacb0f6ed
commit
90ff521e4e
@ -20,8 +20,6 @@ import os
|
|||||||
if not hasattr(__builtins__, 'set'):
|
if not hasattr(__builtins__, 'set'):
|
||||||
from sets import Set as set
|
from sets import Set as set
|
||||||
|
|
||||||
attribute_transforms = {'Admin': lambda cls: AdminOptions(**dict([(k,v) for (k,v) in cls.__dict__.items() if not k.startswith('_')]))}
|
|
||||||
|
|
||||||
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):
|
||||||
@ -109,9 +107,8 @@ class Model(object):
|
|||||||
dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self)
|
dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self)
|
||||||
|
|
||||||
def add_to_class(cls, name, attribute):
|
def add_to_class(cls, name, attribute):
|
||||||
transform = attribute_transforms.get(name, None)
|
if name == 'Admin':
|
||||||
if transform:
|
attribute = AdminOptions(**dict([(k, v) for k, v in attribute.__dict__.items() if not k.startswith('_')]))
|
||||||
attribute = transform(attribute)
|
|
||||||
if hasattr(attribute, 'contribute_to_class'):
|
if hasattr(attribute, 'contribute_to_class'):
|
||||||
attribute.contribute_to_class(cls, name)
|
attribute.contribute_to_class(cls, name)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user