本文整理汇总了Python中django.db.models.base.ModelBase.__new__方法的典型用法代码示例。如果您正苦于以下问题:Python ModelBase.__new__方法的具体用法?Python ModelBase.__new__怎么用?Python ModelBase.__new__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.base.ModelBase
的用法示例。
在下文中一共展示了ModelBase.__new__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
# redefine the related name in the foreign key to TournamentNode,
# so classes with the same name (from different apps) won't clash
try:
from tms.models import TournamentNode
except ImportError:
pass
else:
if (TournamentNode in bases and not
('Meta' in attrs and getattr(attrs['Meta'], 'proxy', False))):
attrs['tournamentnode_ptr'] = models.OneToOneField(
TournamentNode,
related_name="%(app_label)s_%(class)s_related",
parent_link=True
)
# add leaf class manager to all subclasses (unless they define their own)
if 'objects' not in attrs:
attrs['objects'] = ThisTypeOnlyManager()
NewNodeType = ModelBase.__new__(cls, name, bases, attrs)
type_id = NewNodeType.get_id()
def node_init(self, *args, **kwargs):
# TODO: preserve custom init method?
models.Model.__init__(self, *args, **kwargs)
if not self.type_id:
self.type_id = type_id
NewNodeType.__init__ = node_init
node_types[type_id] = NewNodeType
return NewNodeType
示例2: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
# inject Profile fields
for k, v in cls.base_fields.items():
if k not in attrs:
attrs[k] = cls.base_fields[k]
model = ModelBase.__new__(cls, name, bases, attrs)
_profiles.append(model)
return model
示例3: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
# inject PageBase fields
for k, v in cls.base_fields.items():
if k not in attrs:
attrs[k] = cls.base_fields[k]
page_cls = ModelBase.__new__(cls, name, bases, attrs)
register(page_cls)
return page_cls
示例4: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
bases = list(bases)
new_class = ModelBase.__new__(cls, name, tuple(bases), attrs)
if new_class._meta.abstract:
pass
return new_class
示例5: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
new_class = ModelBase.__new__(cls, name, bases, attrs)
if hasattr(new_class, 'FreeAdmin'):
new_class.add_to_class('_admin',
FreeAdminWrapper(new_class.FreeAdmin))
else:
new_class.add_to_class('_admin', FreeAdminWrapper())
return new_class
示例6: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(c, name, bases, attrs):
# Rename class
name = '%sVoteSummary' % model._meta.object_name
# This attribute is required for a model to function properly in Django.
attrs['__module__'] = model.__module__
vote_summary_model = ModelBase.__new__(c, name, bases, attrs)
return vote_summary_model
示例7: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
from freenasUI.freeadmin.site import site
new_class = ModelBase.__new__(cls, name, bases, attrs)
if new_class._meta.abstract:
pass
elif hasattr(new_class, 'FreeAdmin'):
site.register(new_class, freeadmin=new_class.FreeAdmin)
return new_class
示例8: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
super_new = ModelBase.__new__(cls, name, bases, attrs)
module_name = camel_to_underscore(name)
model_module = sys.modules[cls.__module__]
app_label = super_new.__module__.split('.')[-2]
db_table = '%s_%s' % (app_label, module_name)
if not getattr(super_new._meta, 'proxy', False):
super_new._meta.db_table = db_table
return super_new
示例9: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(c, name, bases, attrs):
# Rename class
name = 'Historical%s' % model._meta.object_name
# This attribute is required for a model to function properly.
attrs['__module__'] = self._module or model.__module__
# Copy attributes from base class
attrs.update(self.copy_fields(model))
return ModelBase.__new__(c, name, bases, attrs)
示例10: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
from freenasUI.freeadmin.site import site
bases = list(bases)
appPool.hook_model_new(name, bases, attrs)
new_class = ModelBase.__new__(cls, name, tuple(bases), attrs)
if new_class._meta.abstract:
pass
elif hasattr(new_class, 'FreeAdmin'):
site.register(new_class, freeadmin=new_class.FreeAdmin)
return new_class
示例11: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(*args, **kwargs):
new_class = ModelBase.__new__(*args, **kwargs)
new_manager = RowCacheManager()
if not hasattr(new_class, 'objects'):
# Attach a new manager.
new_manager.contribute_to_class(new_class, 'objects')
new_class._default_manager = new_manager
else:
# Mix in the manager into the existing one.
if new_class.objects.__class__ != RowCacheManager and RowCacheManager not in new_class.objects.__class__.__bases__:
new_class.objects.__class__.__bases__ = (RowCacheManager,) + new_class.objects.__class__.__bases__
return new_class
示例12: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs):
"""
Instantiation of the State type.
When this type is created, also create a logging model if required.
"""
if name != 'StateModel' and 'Machine' in attrs:
attrs['state'] = StateField(max_length=100, default='0',
verbose_name=_('state id'),
machine=attrs['Machine'])
# Call class constructor of parent
return ModelBase.__new__(cls, name, bases, attrs)
示例13: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(c, name, bases, attrs):
# Rename class
name = '%sVote' % model._meta.object_name
# This attribute is required for a model to function
# properly in Django.
attrs['__module__'] = model.__module__
vote_model = ModelBase.__new__(c, name, bases, attrs)
_vote_models[vote_model.get_model_name()] = vote_model
return vote_model
示例14: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(cls, name, bases, attrs, **kwds):
new_class = ModelBase.__new__(cls, name, bases, attrs, **kwds)
aldjemy_attrs = {}
for attr_name, attr in attrs.items():
if callable(attr) or isinstance(attr, property):
aldjemy_attrs[attr_name] = attr
new_class.aldjemy_mixin = type(
'AldjemyMixin_' + name, (object,),
aldjemy_attrs,
)
return new_class
示例15: __new__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __new__ [as 别名]
def __new__(c, name, bases, attrs):
if '__unicode__' in attrs:
old_unicode = attrs['__unicode__']
def new_unicode(self):
return '%s (%s)' % (old_unicode(self), self.get_state_info().description)
attrs['__unicode__'] = new_unicode
attrs['__module__'] = state_model.__module__
values = {'model_name': state_model.__name__,
'field_name': field_name.capitalize()}
class_name = conf.LOG_MODEL_NAME % values
return ModelBase.__new__(c, class_name, bases, attrs)