當前位置: 首頁>>代碼示例>>Python>>正文


Python models.MPTTModel方法代碼示例

本文整理匯總了Python中mptt.models.MPTTModel方法的典型用法代碼示例。如果您正苦於以下問題:Python models.MPTTModel方法的具體用法?Python models.MPTTModel怎麽用?Python models.MPTTModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mptt.models的用法示例。


在下文中一共展示了models.MPTTModel方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: formfield_for_foreignkey

# 需要導入模塊: from mptt import models [as 別名]
# 或者: from mptt.models import MPTTModel [as 別名]
def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if issubclass(db_field.rel.to, MPTTModel) \
                and not isinstance(db_field, TreeForeignKey) \
                and db_field.name not in self.raw_id_fields:
            db = kwargs.get('using')

            limit_choices_to = db_field.get_limit_choices_to()
            defaults = dict(
                form_class=TreeNodeChoiceField,
                queryset=db_field.rel.to._default_manager.using(
                    db).complex_filter(limit_choices_to),
                required=False)
            defaults.update(kwargs)
            kwargs = defaults
        return super(MPTTModelAdmin, self).formfield_for_foreignkey(
            db_field, request, **kwargs) 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:18,代碼來源:admin.py

示例2: add_object_relation

# 需要導入模塊: from mptt import models [as 別名]
# 或者: from mptt.models import MPTTModel [as 別名]
def add_object_relation(self, obj):
        content_type = ContentType.objects.get_for_model(obj)
        is_mptt = isinstance(obj, MPTTModel)
        rel = ArticleForObject.objects.get_or_create(article=self,
                                                     content_type=content_type,
                                                     object_id=obj.id,
                                                     is_mptt=is_mptt)
        return rel 
開發者ID:hackerspace-ntnu,項目名稱:website,代碼行數:10,代碼來源:article.py

示例3: add_syncable_models

# 需要導入模塊: from mptt import models [as 別名]
# 或者: from mptt.models import MPTTModel [as 別名]
def add_syncable_models():
    """
    Per profile, adds each model to a dictionary mapping the morango model name to its model class.
    We sort by ForeignKey dependencies to safely sync data.
    """

    import django.apps
    from morango.models import SyncableModel
    from morango.manager import SyncableModelManager
    from morango.query import SyncableModelQuerySet

    model_list = []
    for model_class in django.apps.apps.get_models():
        # several validation checks to assert models will be syncing correctly
        if issubclass(model_class, SyncableModel):
            name = model_class.__name__
            if _multiple_self_ref_fk_check(model_class):
                raise InvalidMorangoModelConfiguration("Syncing models with more than 1 self referential ForeignKey is not supported.")
            try:
                from mptt import models
                from morango.utils.morango_mptt import MorangoMPTTModel, MorangoMPTTTreeManager, MorangoTreeQuerySet
                # mptt syncable model checks
                if issubclass(model_class, models.MPTTModel):
                    if not issubclass(model_class, MorangoMPTTModel):
                        raise InvalidMorangoModelConfiguration("{} that inherits from MPTTModel, should instead inherit from MorangoMPTTModel.".format(name))
                    if not isinstance(model_class.objects, MorangoMPTTTreeManager):
                        raise InvalidMPTTManager("Manager for {} must inherit from MorangoMPTTTreeManager.".format(name))
                    if not isinstance(model_class.objects.none(), MorangoTreeQuerySet):
                        raise InvalidMPTTQuerySet("Queryset for {} model must inherit from MorangoTreeQuerySet.".format(name))
            except ImportError:
                pass
            # syncable model checks
            if not isinstance(model_class.objects, SyncableModelManager):
                raise InvalidSyncableManager("Manager for {} must inherit from SyncableModelManager.".format(name))
            if not isinstance(model_class.objects.none(), SyncableModelQuerySet):
                raise InvalidSyncableQueryset("Queryset for {} model must inherit from SyncableModelQuerySet.".format(name))
            if model_class._meta.many_to_many:
                raise UnsupportedFieldType("{} model with a ManyToManyField is not supported in morango.")
            if not hasattr(model_class, 'morango_model_name'):
                raise InvalidMorangoModelConfiguration("{} model must define a morango_model_name attribute".format(name))
            if not hasattr(model_class, 'morango_profile'):
                raise InvalidMorangoModelConfiguration("{} model must define a morango_profile attribute".format(name))

            # create empty list to hold model classes for profile if not yet created
            profile = model_class.morango_profile
            _profile_models[profile] = _profile_models.get(profile, [])

            # don't sync models where morango_model_name is None
            if model_class.morango_model_name is not None:
                _insert_model_into_profile_dict(model_class, profile)

    # for each profile, create a dict mapping from morango model names to model class
    for profile, model_list in iteritems(_profile_models):
        syncable_models_dict = OrderedDict()
        for model_class in model_list:
            syncable_models_dict[model_class.morango_model_name] = model_class
        _profile_models[profile] = syncable_models_dict 
開發者ID:learningequality,項目名稱:morango,代碼行數:59,代碼來源:register_models.py


注:本文中的mptt.models.MPTTModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。