本文整理汇总了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)
示例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)
示例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)