本文整理汇总了Python中django.contrib.admin.filterspecs.FilterSpec.register_first方法的典型用法代码示例。如果您正苦于以下问题:Python FilterSpec.register_first方法的具体用法?Python FilterSpec.register_first怎么用?Python FilterSpec.register_first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.filterspecs.FilterSpec
的用法示例。
在下文中一共展示了FilterSpec.register_first方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PermsFilterSpec
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import register_first [as 别名]
class PermsFilterSpec(FilterSpec):
def __init__(self, f, request, params, model, model_admin):
super(PermsFilterSpec, self).__init__(f, request, params, model, model_admin)
self.lookup_title = f.verbose_name
#rel_name = f.rel.get_related_field().name
#c = f.name
#xx = f.rel.get_related_field()
self.lookup_kwarg = PERMS_VAR
self.lookup_val = request.GET.get(PERMS_VAR, None)
self.lookup_choices = UserPermission.objects.all().order_by('id')
def has_output(self):
return len(self.lookup_choices) > 1
def title(self):
return self.lookup_title
def choices(self, cl):
yield {'selected': self.lookup_val is None,
'query_string': '?',
'display': _('All')}
for up in self.lookup_choices:
yield {'selected': self.lookup_val == smart_unicode(up.id),
'query_string': cl.get_query_string({self.lookup_kwarg: up.id}),
'display': up.name}
FilterSpec.register_first(lambda f: bool(f.name == 'user_permissions'), PermsFilterSpec)
示例2: has_output
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import register_first [as 别名]
def has_output(self):
return len(self.lookup_choices) > 1
def title(self):
return self.lookup_title
def choices(self, cl):
yield {'selected': self.lookup_val is None,
'query_string': '?',
'display': _('All')}
for up in self.lookup_choices:
yield {'selected': self.lookup_val == smart_unicode(up.id),
'query_string': cl.get_query_string({self.lookup_kwarg: up.id}),
'display': up.name_cn}
FilterSpec.register_first(lambda f: bool(f.name == 'visit_begin'), AreaFilterSpec)
class DealerTypeFilterSpec(FilterSpec):
def __init__(self, f, request, params, model, model_admin):
super(DealerTypeFilterSpec, self).__init__(f, request, params, model, model_admin)
self.lookup_title = u'经销商'
#rel_name = f.rel.get_related_field().name
#c = f.name
#xx = f.rel.get_related_field()
self.lookup_kwarg = DEALER_TYPE_VAR
self.lookup_val = request.GET.get(DEALER_TYPE_VAR, None)
self.lookup_choices = DealerType.objects.all().order_by('id')
def has_output(self):
return len(self.lookup_choices) > 1
示例3: __init__
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import register_first [as 别名]
accords = models.TextField(u'Аккорды', blank=True)
translation = models.TextField(u'Перевод песни', blank=True)
accords.test_null_filter = True
translation.test_null_filter = True
"""
def __init__(self, f, request, params, model, model_admin):
super(EmptyStringFilterSpec, self).__init__(f, request, params, model, model_admin)
self.lookup_kwarg = '%s__exact' % f.name
self.lookup_kwarg2 = '%s__gt' % f.name
self.lookup_kwarg3 = '%s__isnull' % f.name
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_val2 = request.GET.get(self.lookup_kwarg2, None)
def title(self):
return u"наличие поля '%s'" % self.field.verbose_name
def choices(self, cl):
yield {'selected': self.lookup_val2 is None and self.lookup_val is None,
'query_string': cl.get_query_string({}, [self.lookup_kwarg2, self.lookup_kwarg, self.lookup_kwarg3]),
'display': u'Все'}
yield {'selected': self.lookup_val2 == '' and self.lookup_val is None,
'query_string': cl.get_query_string({self.lookup_kwarg2: ''}, [self.lookup_kwarg, self.lookup_kwarg3]),
'display': u'Имеется'}
yield {'selected': self.lookup_val == '' and self.lookup_val2 is None,
'query_string': cl.get_query_string({self.lookup_kwarg: ''}, [self.lookup_kwarg2, self.lookup_kwarg3]),
'display': u'Отсутствует'}
FilterSpec.register_first(lambda f: hasattr(f, 'test_null_filter'), EmptyStringFilterSpec)