本文整理汇总了Python中django.contrib.admin.filterspecs.FilterSpec.create方法的典型用法代码示例。如果您正苦于以下问题:Python FilterSpec.create方法的具体用法?Python FilterSpec.create怎么用?Python FilterSpec.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.filterspecs.FilterSpec
的用法示例。
在下文中一共展示了FilterSpec.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import create [as 别名]
def render(self, context):
filters = []
request = context['request']
app_name = self.app_name.resolve(context)
model_name = self.model_name.resolve(context)
field_name = self.field_name.resolve(context)
if self.choices_queryset is not None:
choices_queryset = self.choices_queryset.resolve(context)
else:
choices_queryset = None
model = models.get_model(app_name, model_name)
qsm = QueryStringManager(request)
params = qsm.get_params()
if params.get('page', None):
del params['page']
field = model._meta.get_field(field_name)
if field.get_internal_type() == 'FileField':
spec = FieldAvailabilityValueFilterSpec(field, request, params, model, None)
elif self.multiselection and (field.rel is not None): # is a related field (ForeignKeyField)
spec = MultipleRelatedFilterSpec(field, request, params, model, None, choices_queryset)
else: # normal filter spec
spec = FilterSpec.create(field, request, params, model, None)
filter_context = {'title': spec.title(), 'choices' : list(spec.choices(qsm))}
tpl = loader.get_template('admin/filter.html')
return tpl.render(Context(dict(filter_context, autoescape=context.autoescape)))
示例2: get_filters
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import create [as 别名]
def get_filters(self, request):
filter_specs = []
if self.list_filter:
filter_fields = [self.lookup_opts.get_field(field_name) for field_name in self.list_filter]
for f in filter_fields:
spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
if spec and spec.has_output():
filter_specs.append(spec)
return filter_specs, bool(filter_specs)
示例3: get_filters
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import create [as 别名]
def get_filters(self, request):
filter_specs = []
if self.list_filter:
for filter_name in self.list_filter:
field = get_fields_from_path(self.model, filter_name)[-1]
spec = FilterSpec.create(field, request, self.params,
self.model, self.model_admin,
field_path=filter_name)
if spec and spec.has_output():
filter_specs.append(spec)
return filter_specs, bool(filter_specs)
示例4: get_filters
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import create [as 别名]
def get_filters(self, request):
filter_specs = []
if self.list_filter:
lookup_opts = self.lookup_opts
for filter_name in self.list_filter:
if '__' in filter_name:
f = None
model = self.model
path = filter_name.split('__')
for field_name in path[:-1]:
f = model._meta.get_field(field_name)
model = f.rel.to
f = model._meta.get_field(path[-1])
spec = FilterSpec.create(f, request, self.params, model, self.model_admin, field_path=filter_name)
else:
f = lookup_opts.get_field(filter_name)
spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
if spec and spec.has_output():
filter_specs.append(spec)
return filter_specs, bool(filter_specs)
示例5: get_filters
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import create [as 别名]
def get_filters(self, request):
filter_specs = []
if self.list_filter:
filter_fields = []
for field_name in self.list_filter:
if '__' in field_name:
names = field_name.split('__')
field = FakeField(name = names[0], rel_fields = names)
else:
field = self.lookup_opts.get_field(field_name)
filter_fields.append(field)
for f in filter_fields:
spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
if spec and spec.has_output():
filter_specs.append(spec)
return filter_specs, bool(filter_specs)
示例6: get_filters
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import create [as 别名]
def get_filters(self, request):
# Esto lo modificamos para que en el filtro solo aparezcan opciones con
# datos (por ejemplo, en la vista dispositivos solo aparezcan en el
# filtro de localidad las localidades que tienen dispositivos
filter_specs = []
if self.list_filter:
for filter_name in self.list_filter:
field = get_fields_from_path(self.model, filter_name)[-1]
spec = FilterSpec.create(field, request, self.params,
self.model, self.model_admin,
field_path=filter_name)
#Salva:
if isinstance(spec, RelatedFilterSpec) and not '__' in filter_name:
spec.lookup_choices = [(x._get_pk_val(),x.__unicode__()) for x in field.rel.to.objects.annotate(num_rel=Count(self.model._meta.verbose_name)).filter(num_rel__gt=0)] #IGNORE:W0212
#Fin Modificacion
if spec and spec.has_output():
filter_specs.append(spec)
return filter_specs, bool(filter_specs)