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


Python FilterSpec.register_first方法代码示例

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

开发者ID:cswxin,项目名称:bmw_apq,代码行数:30,代码来源:permfilter.py

示例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
开发者ID:cswxin,项目名称:bmw_apq,代码行数:33,代码来源:paperfilter.py

示例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)
开发者ID:harutold,项目名称:django_utils,代码行数:32,代码来源:filterspecs.py


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