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


Python FilterSpec.__init__方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import __init__ [as 别名]
 def __init__(self, f, request, params, model, model_admin):
     FilterSpec.__init__(self, f, request, params, model, model_admin)
     self.model = model
     self.lookup_val = request.GET.get(f, None)
开发者ID:CARocha,项目名称:django-reporting-1,代码行数:6,代码来源:filterspecs.py

示例2: __init__

# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import __init__ [as 别名]
    def __init__(self, f, request, params, model, model_admin, **kwargs):
        filter_by_key = f.name+'_fk_filter_by'
        filter_by_val = getattr(model_admin, filter_by_key, None)

        filter_related_key = f.name+'_fk_filter_related_only'
        filter_related_val = getattr(model_admin, filter_related_key, False)

        filter_nf_key = f.name+'_fk_filter_display_field'
        if filter_by_val:
            filter_nf_val = getattr(model_admin, filter_nf_key, filter_by_val)
        else:
            filter_nf_val = getattr(model_admin, filter_nf_key, 'pk')

        filter_crit_key = f.name+'_fk_filter_criteria_fn'
        filter_crit_fn = getattr(model_admin, filter_crit_key, None)

        filter_qs_key = f.name+'_fk_filter_query_string'
        self.filter_qs_val = getattr(model_admin, filter_qs_key, {})

        if filter_by_val:
            self.fk_filter_on = True
            # we call FilterSpec constructor, not RelatedFilterSpec
            # constructor; RelatedFilterSpec constructor will try to
            # get all the pk values on the related models, which we
            # won't need.
            FilterSpec.__init__(self, f, request, params, model, model_admin)

            filter_name_key = f.name+'_fk_filter_name'
            filter_name_val = getattr(model_admin, filter_name_key, None)

            if filter_name_val is None:

                self.lookup_title = f.verbose_name
            else:
                self.lookup_title = f.verbose_name+' '+filter_name_val

            self.lookup_kwarg = f.name+'__'+filter_by_val+'__exact'
            self.lookup_val = request.GET.get(self.lookup_kwarg, None)

            if filter_related_val:
                try:
                    qs = model_admin.queryset(request)
                    if filter_crit_fn is not None:
                        qs = filter_crit_fn(qs)
                    qs = qs.values_list((f.name + '__' + filter_by_val,
                                         f.name + '__' + filter_nf_val)
                                        .order_by(f.name + '__' +
                                        filter_nf_val).distinct())
                except Exception:
                    # Django QuerySet can't follow generic
                    # relationships using __, so we have to use
                    # f.rel.to.objects
                    qs = f.rel.to.objects
                    if filter_crit_fn is not None:
                        qs = filter_crit_fn(qs)
                    qs = qs.values_list(filter_by_val,
                                        filter_nf_val).distinct()
            else:
                qs = f.rel.to.objects
                if filter_crit_fn is not None:
                    qs = filter_crit_fn(qs)
                qs = qs.values_list(filter_by_val, filter_nf_val).distinct()

            self.lookup_choices = list(set(qs))
            self.lookup_choices.sort(reverse=True)
            # if there was a further limiting criteria, then we want
            # to make sure we still display the filter even if there

            # is only one option
            if filter_crit_fn is not None and len(self.lookup_choices) == 1:
                self.lookup_choices = self.lookup_choices+[('', ''), ]

        else:
            self.fk_filter_on = False
            RelatedFilterSpec.__init__(self, f, request, params, model,
                                       model_admin)

            if filter_related_val:
                qs = model_admin.queryset(request)
                if filter_crit_fn is not None:
                    qs = filter_crit_fn(qs)
                qs = qs.values_list((f.name+'__pk', f.name+'__'+filter_nf_val)
                                    .order_by(f.name+'__'+filter_nf_val)
                                    .distinct())
                self.lookup_choices = list(qs)
开发者ID:dtamez,项目名称:cerc,代码行数:87,代码来源:fk_filter.py

示例3: __init__

# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import __init__ [as 别名]
 def __init__(self, f, request, params, model, model_admin):
     field = get_fields_from_path(model, f)[-1]
     FilterSpec.__init__(self, field, request, params, model, model_admin, field_path=f)
     self.model = model
     self.lookup_val = request.GET.get(f, None)
开发者ID:vladimir-iliev,项目名称:django-reporting,代码行数:7,代码来源:filterspecs.py


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