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


Python utils._get_field函数代码示例

本文整理汇总了Python中taggit.utils._get_field函数的典型用法代码示例。如果您正苦于以下问题:Python _get_field函数的具体用法?Python _get_field怎么用?Python _get_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _get_mm_case_path_info

 def _get_mm_case_path_info(self, direct=False):
     pathinfos = []
     linkfield1 = _get_field(self.through, 'content_object')
     linkfield2 = _get_field(self.through, self.m2m_reverse_field_name())
     if direct:
         join1infos = linkfield1.get_reverse_path_info()
         join2infos = linkfield2.get_path_info()
     else:
         join1infos = linkfield2.get_reverse_path_info()
         join2infos = linkfield1.get_path_info()
     pathinfos.extend(join1infos)
     pathinfos.extend(join2infos)
     return pathinfos
开发者ID:jdufresne,项目名称:django-taggit,代码行数:13,代码来源:managers.py

示例2: _get_gfk_case_path_info

 def _get_gfk_case_path_info(self, direct=False):
     pathinfos = []
     from_field = self.model._meta.pk
     opts = self.through._meta
     object_id_field = _get_field(self.through, 'object_id')
     linkfield = _get_field(self.through, self.m2m_reverse_field_name())
     if direct:
         join1infos = [PathInfo(self.model._meta, opts, [from_field], self.rel, True, False)]
         join2infos = linkfield.get_path_info()
     else:
         join1infos = linkfield.get_reverse_path_info()
         join2infos = [PathInfo(opts, self.model._meta, [object_id_field], self, True, False)]
     pathinfos.extend(join1infos)
     pathinfos.extend(join2infos)
     return pathinfos
开发者ID:jbkkd,项目名称:django-taggit,代码行数:15,代码来源:managers.py

示例3: similar_objects

    def similar_objects(self):
        lookup_kwargs = self._lookup_kwargs()
        lookup_keys = sorted(lookup_kwargs)
        qs = self.through.objects.values(*six.iterkeys(lookup_kwargs))
        qs = qs.annotate(n=models.Count("pk"))
        qs = qs.exclude(**lookup_kwargs)
        qs = qs.filter(tag__in=self.all())
        qs = qs.order_by("-n")

        # TODO: This all feels like a bit of a hack.
        items = {}
        if len(lookup_keys) == 1:
            # Can we do this without a second query by using a select_related()
            # somehow?
            f = _get_field(self.through, lookup_keys[0])
            objs = f.rel.to._default_manager.filter(**{"%s__in" % f.rel.field_name: [r["content_object"] for r in qs]})
            for obj in objs:
                items[(getattr(obj, f.rel.field_name),)] = obj
        else:
            preload = {}
            for result in qs:
                preload.setdefault(result["content_type"], set())
                preload[result["content_type"]].add(result["object_id"])

            for ct, obj_ids in preload.items():
                ct = ContentType.objects.get_for_id(ct)
                for obj in ct.model_class()._default_manager.filter(pk__in=obj_ids):
                    items[(ct.pk, obj.pk)] = obj

        results = []
        for result in qs:
            obj = items[tuple(result[k] for k in lookup_keys)]
            obj.similar_tags = result["n"]
            results.append(obj)
        return results
开发者ID:russmo,项目名称:django-taggit,代码行数:35,代码来源:managers.py

示例4: _get_subclasses

def _get_subclasses(model):
    subclasses = [model]
    if VERSION < (1, 8):
        all_fields = (_get_field(model, f) for f in model._meta.get_all_field_names())
    else:
        all_fields = model._meta.get_fields()
    for field in all_fields:
        # Django 1.8 +
        if not RelatedObject and isinstance(field, OneToOneRel) and getattr(field.field.rel, "parent_link", None):
            subclasses.extend(_get_subclasses(field.related_model))

        # < Django 1.8
        if RelatedObject and isinstance(field, RelatedObject) and getattr(field.field.rel, "parent_link", None):
            subclasses.extend(_get_subclasses(field.model))
    return subclasses
开发者ID:russmo,项目名称:django-taggit,代码行数:15,代码来源:managers.py

示例5: similar_objects

    def similar_objects(self):
        lookup_kwargs = self._lookup_kwargs()
        lookup_keys = sorted(lookup_kwargs)
        qs = self.through.objects.values(*six.iterkeys(lookup_kwargs))
        qs = qs.annotate(n=models.Count('pk'))
        qs = qs.exclude(**lookup_kwargs)
        qs = qs.filter(tag__in=self.all())
        qs = qs.order_by('-n')

        # TODO: This all feels like a bit of a hack.
        items = {}
        if len(lookup_keys) == 1:
            # Can we do this without a second query by using a select_related()
            # somehow?
            f = _get_field(self.through, lookup_keys[0])
            remote_field = _remote_field(f)
            rel_model = _related_model(_remote_field(f))
            objs = rel_model._default_manager.filter(**{
                "%s__in" % remote_field.field_name: [r["content_object"] for r in qs]
            })
            for obj in objs:
                items[(getattr(obj, remote_field.field_name),)] = obj
        else:
            preload = {}
            for result in qs:
                preload.setdefault(result['content_type'], set())
                preload[result["content_type"]].add(result["object_id"])

            for ct, obj_ids in preload.items():
                ct = ContentType.objects.get_for_id(ct)
                model_class = ct.model_class()
                if model_class is None:
                    # obsolete content type. Skip it.
                    continue
                for obj in model_class._default_manager.filter(pk__in=obj_ids):
                    items[(ct.pk, obj.pk)] = obj

        results = []
        for result in qs:
            res_items = tuple(result[k] for k in lookup_keys)
            if res_items not in items:
                continue
            obj = items[res_items]
            obj.similar_tags = result["n"]
            results.append(obj)
        return results
开发者ID:texastribune,项目名称:django-taggit,代码行数:46,代码来源:managers.py

示例6: get_extra_join_sql

 def get_extra_join_sql(self, connection, qn, lhs_alias, rhs_alias):
     model_name = _model_name(self.through)
     if rhs_alias == "%s_%s" % (self.through._meta.app_label, model_name):
         alias_to_join = rhs_alias
     else:
         alias_to_join = lhs_alias
     extra_col = _get_field(self.through, "content_type").column
     content_type_ids = [ContentType.objects.get_for_model(subclass).pk for subclass in _get_subclasses(self.model)]
     if len(content_type_ids) == 1:
         content_type_id = content_type_ids[0]
         extra_where = " AND %s.%s = %%s" % (qn(alias_to_join), qn(extra_col))
         params = [content_type_id]
     else:
         extra_where = " AND %s.%s IN (%s)" % (
             qn(alias_to_join),
             qn(extra_col),
             ",".join(["%s"] * len(content_type_ids)),
         )
         params = content_type_ids
     return extra_where, params
开发者ID:russmo,项目名称:django-taggit,代码行数:20,代码来源:managers.py

示例7: related_fields

 def related_fields(self):
     return [(_get_field(self.through, 'object_id'), self.model._meta.pk)]
开发者ID:jdufresne,项目名称:django-taggit,代码行数:2,代码来源:managers.py

示例8: get_extra_restriction

 def get_extra_restriction(self, where_class, alias, related_alias):
     extra_col = _get_field(self.through, 'content_type').column
     content_type_ids = [ContentType.objects.get_for_model(subclass).pk
                         for subclass in _get_subclasses(self.model)]
     return ExtraJoinRestriction(related_alias, extra_col, content_type_ids)
开发者ID:jdufresne,项目名称:django-taggit,代码行数:5,代码来源:managers.py

示例9: m2m_reverse_field_name

 def m2m_reverse_field_name(self):
     return _get_field(self.through, 'tag').name
开发者ID:jdufresne,项目名称:django-taggit,代码行数:2,代码来源:managers.py

示例10: tag_relname

 def tag_relname(cls):
     return _get_field(cls, 'tag').rel.related_name
开发者ID:GarrusRiflle,项目名称:fuck_github,代码行数:2,代码来源:models.py

示例11: tag_model

 def tag_model(cls):
     return _get_field(cls, 'tag').rel.to
开发者ID:GarrusRiflle,项目名称:fuck_github,代码行数:2,代码来源:models.py

示例12: m2m_reverse_name

 def m2m_reverse_name(self):
     return _get_field(self.through, "tag").column
开发者ID:russmo,项目名称:django-taggit,代码行数:2,代码来源:managers.py

示例13: tag_relname

 def tag_relname(cls):
     field = _get_field(cls, 'tag')
     return field.remote_field.related_name if VERSION >= (1, 9) else field.rel.related_name
开发者ID:liyaopinner,项目名称:django-taggit,代码行数:3,代码来源:models.py

示例14: tag_model

 def tag_model(cls):
     field = _get_field(cls, 'tag')
     return field.remote_field.model if VERSION >= (1, 9) else field.rel.to
开发者ID:liyaopinner,项目名称:django-taggit,代码行数:3,代码来源:models.py


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