本文整理汇总了Python中django.db.models.base.ModelBase.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ModelBase.__init__方法的具体用法?Python ModelBase.__init__怎么用?Python ModelBase.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.base.ModelBase
的用法示例。
在下文中一共展示了ModelBase.__init__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __init__ [as 别名]
def __init__(cls, class_name, bases, attrs):
# Don't execute for Gallery itself
if [b for b in bases if isinstance(b, GalleryBase)]:
try:
gallery_meta = getattr(cls, 'GalleryMeta')
except AttributeError:
raise GalleryMetaNotDefined('%s must define GalleryMeta.' %
class_name)
try:
member_models = getattr(gallery_meta, 'member_models')
except AttributeError:
raise MemberModelsNotDefined(
'%s.GalleryMeta must define a list of member_models.' %
class_name)
gallery_meta.gallery_class = cls
cls._gallery_meta = gallery_meta
membership_verbose_name = '%s Membership' % cls._meta.verbose_name
custom_membership = getattr(gallery_meta, 'membership_class', None)
if custom_membership:
membership_class_name = '%sBaseMembership' % class_name
else:
membership_class_name = '%sMembership' % class_name
module_name = cls.__module__
membership_class = _create_membership_class(
class_name=membership_class_name,
verbose_name=membership_verbose_name,
app_label=cls._meta.app_label,
module_name=module_name,
member_models=member_models,
abstract=bool(custom_membership),
gallery_class=cls,
)
if custom_membership:
cls.BaseMembership = membership_class
module = importlib.import_module(module_name)
class Descriptor(object):
def __get__(self, instance, owner):
return getattr(module, custom_membership)
cls.Membership = Descriptor()
else:
cls.Membership = membership_class
ModelBase.__init__(cls, class_name, bases, attrs)
示例2: __init__
# 需要导入模块: from django.db.models.base import ModelBase [as 别名]
# 或者: from django.db.models.base.ModelBase import __init__ [as 别名]
def __init__(self, name, bases, attrs):
ModelBase.__init__(self, name, bases, attrs)
if not self._meta.abstract:
MetaQueue.IMPLEMENTATIONS.append(self)