当前位置: 首页>>代码示例>>Python>>正文


Python ModelBase.__new__方法代码示例

本文整理汇总了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
开发者ID:martymarty,项目名称:sctms,代码行数:37,代码来源:models.py

示例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
开发者ID:pombredanne,项目名称:django-profilebase,代码行数:10,代码来源:models.py

示例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
开发者ID:pombredanne,项目名称:django-pagebase,代码行数:10,代码来源:base.py

示例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
开发者ID:williambr,项目名称:middleware,代码行数:10,代码来源:__init__.py

示例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
开发者ID:BillTheBest,项目名称:MetaNAS,代码行数:11,代码来源:models.py

示例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
开发者ID:avoine,项目名称:django-votes,代码行数:12,代码来源:models.py

示例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
开发者ID:avontd2868,项目名称:freenas,代码行数:12,代码来源:__init__.py

示例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
开发者ID:devhub,项目名称:Django-facebook,代码行数:13,代码来源:models.py

示例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)
开发者ID:jasuca,项目名称:django-historicalrecords,代码行数:13,代码来源:models.py

示例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
开发者ID:freenas,项目名称:freenas,代码行数:14,代码来源:__init__.py

示例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
开发者ID:apnarm,项目名称:django-lazycache,代码行数:14,代码来源:__init__.py

示例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)
开发者ID:vartagg,项目名称:django-states2,代码行数:15,代码来源:models.py

示例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
开发者ID:jirfag,项目名称:qhonuskan-votes,代码行数:15,代码来源:models.py

示例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
开发者ID:Cyril-Roques,项目名称:aldjemy,代码行数:16,代码来源:meta.py

示例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)
开发者ID:ramn,项目名称:django-states2,代码行数:16,代码来源:log.py


注:本文中的django.db.models.base.ModelBase.__new__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。