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


Python fields.ParentalManyToManyField方法代码示例

本文整理汇总了Python中modelcluster.fields.ParentalManyToManyField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.ParentalManyToManyField方法的具体用法?Python fields.ParentalManyToManyField怎么用?Python fields.ParentalManyToManyField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在modelcluster.fields的用法示例。


在下文中一共展示了fields.ParentalManyToManyField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_all_child_m2m_relations

# 需要导入模块: from modelcluster import fields [as 别名]
# 或者: from modelcluster.fields import ParentalManyToManyField [as 别名]
def get_all_child_m2m_relations(model):
    """
    Return a list of ParentalManyToManyFields on the given model,
    including ones attached to ancestors of the model
    """
    return [
        field for field in model._meta.get_fields()
        if isinstance(field, ParentalManyToManyField)
    ] 
开发者ID:wagtail,项目名称:django-modelcluster,代码行数:11,代码来源:models.py

示例2: select_on_queryset

# 需要导入模块: from modelcluster import fields [as 别名]
# 或者: from modelcluster.fields import ParentalManyToManyField [as 别名]
def select_on_queryset(self, queryset):
        """
        This method runs either prefetch_related or select_related on the queryset
        to improve indexing speed of the relation.

        It decides which method to call based on the number of related objects:
         - single (eg ForeignKey, OneToOne), it runs select_related
         - multiple (eg ManyToMany, reverse ForeignKey) it runs prefetch_related
        """
        try:
            field = self.get_field(queryset.model)
        except FieldDoesNotExist:
            return queryset

        if isinstance(field, RelatedField) and not isinstance(field, ParentalManyToManyField):
            if field.many_to_one or field.one_to_one:
                queryset = queryset.select_related(self.field_name)
            elif field.one_to_many or field.many_to_many:
                queryset = queryset.prefetch_related(self.field_name)

        elif isinstance(field, ForeignObjectRel):
            # Reverse relation
            if isinstance(field, OneToOneRel):
                # select_related for reverse OneToOneField
                queryset = queryset.select_related(self.field_name)
            else:
                # prefetch_related for anything else (reverse ForeignKey/ManyToManyField)
                queryset = queryset.prefetch_related(self.field_name)

        return queryset 
开发者ID:wagtail,项目名称:wagtail,代码行数:32,代码来源:index.py


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