本文整理汇总了Python中django.contrib.admin.filterspecs.FilterSpec.register方法的典型用法代码示例。如果您正苦于以下问题:Python FilterSpec.register方法的具体用法?Python FilterSpec.register怎么用?Python FilterSpec.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.filterspecs.FilterSpec
的用法示例。
在下文中一共展示了FilterSpec.register方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NullFilterSpec
# 需要导入模块: from django.contrib.admin.filterspecs import FilterSpec [as 别名]
# 或者: from django.contrib.admin.filterspecs.FilterSpec import register [as 别名]
class NullFilterSpec(FilterSpec):
def __init__(self, f, request, params, model, model_admin, field_path=None):
super(NullFilterSpec, self).__init__(f, request, params, model, model_admin)
self.lookup_kwarg = '%s__isnull' % f.name
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
def choices(self, cl):
yield {'selected': self.lookup_val is None,
'query_string': cl.get_query_string({}, [self.lookup_kwarg]),
'display': _('All')}
for k, v in ((True,_('Null')),('',_('With value'))):
yield {'selected': k == self.lookup_val,
'query_string': cl.get_query_string({self.lookup_kwarg: k}),
'display': v}
FilterSpec.register(lambda f: f.null, NullFilterSpec)
from django.db import models
class DateRangeFilterSpec(FilterSpec):
USE_OUTPUT_FUNC = True
template = 'xadmin/widgets/date_range_filter.html'
def __init__(self, f, request, params, model, model_admin, field_path=None):
super(DateRangeFilterSpec, self).__init__(f, request, params, model, model_admin)
self._from = request.GET.get('born__gte', "")
self._to = request.GET.get('born__lte', "")
def title(self):
return self.field.verbose_name