@@ -26,38 +26,44 @@ class ParentFieldListFilter(ChoicesFieldListFilter):
2626 my_model_field.page_parent_filter = True
2727 """
2828
29- def __init__ (self , f , request , params , model , model_admin ,
30- field_path = None ):
29+ def __init__ (self , f , request , params , model , model_admin , field_path = None ):
3130 super (ParentFieldListFilter , self ).__init__ (
32- f , request , params , model , model_admin , field_path )
31+ f , request , params , model , model_admin , field_path
32+ )
3333
34- parent_ids = model .objects .exclude (parent = None ).values_list (
35- "parent__id" , flat = True ).order_by ("parent__id" ).distinct ()
34+ parent_ids = (
35+ model .objects .exclude (parent = None )
36+ .values_list ("parent__id" , flat = True )
37+ .order_by ("parent__id" )
38+ .distinct ()
39+ )
3640 parents = model .objects .filter (pk__in = parent_ids ).values_list (
37- "pk" , "title" , "level" )
38- self .lookup_choices = [(
39- pk ,
40- "%s%s" % (
41- " " * level ,
42- shorten_string (title , max_length = 25 )),
43- ) for pk , title , level in parents ]
41+ "pk" , "title" , "level"
42+ )
43+ self .lookup_choices = [
44+ (
45+ pk ,
46+ "%s%s" % (" " * level , shorten_string (title , max_length = 25 )),
47+ )
48+ for pk , title , level in parents
49+ ]
4450
4551 def choices (self , cl ):
4652 yield {
47- ' selected' : self .lookup_val is None ,
48- ' query_string' : cl .get_query_string ({}, [self .lookup_kwarg ]),
49- ' display' : _ (' All' )
53+ " selected" : self .lookup_val is None ,
54+ " query_string" : cl .get_query_string ({}, [self .lookup_kwarg ]),
55+ " display" : _ (" All" ),
5056 }
5157
5258 for pk , title in self .lookup_choices :
5359 yield {
54- ' selected' : pk == int (self .lookup_val or '0' ),
55- ' query_string' : cl .get_query_string ({self .lookup_kwarg : pk }),
56- ' display' : mark_safe (smart_text (title ))
60+ " selected" : pk == int (self .lookup_val or "0" ),
61+ " query_string" : cl .get_query_string ({self .lookup_kwarg : pk }),
62+ " display" : mark_safe (smart_text (title )),
5763 }
5864
5965 def title (self ):
60- return _ (' Parent' )
66+ return _ (" Parent" )
6167
6268
6369class CategoryFieldListFilter (ChoicesFieldListFilter ):
@@ -67,10 +73,10 @@ class CategoryFieldListFilter(ChoicesFieldListFilter):
6773 my_model_field.category_filter = True
6874 """
6975
70- def __init__ (self , f , request , params , model , model_admin ,
71- field_path = None ):
76+ def __init__ (self , f , request , params , model , model_admin , field_path = None ):
7277 super (CategoryFieldListFilter , self ).__init__ (
73- f , request , params , model , model_admin , field_path )
78+ f , request , params , model , model_admin , field_path
79+ )
7480
7581 # Restrict results to categories which are actually in use:
7682 if DJANGO_VERSION < (1 , 8 ):
@@ -85,7 +91,7 @@ def __init__(self, f, request, params, model, model_admin,
8591
8692 self .lookup_choices = sorted (
8793 [
88- (i .pk , ' %s (%s)' % (i , i ._related_count ))
94+ (i .pk , " %s (%s)" % (i , i ._related_count ))
8995 for i in related_model .objects .annotate (
9096 _related_count = Count (related_name )
9197 ).exclude (_related_count = 0 )
@@ -95,17 +101,17 @@ def __init__(self, f, request, params, model, model_admin,
95101
96102 def choices (self , cl ):
97103 yield {
98- ' selected' : self .lookup_val is None ,
99- ' query_string' : cl .get_query_string ({}, [self .lookup_kwarg ]),
100- ' display' : _ (' All' )
104+ " selected" : self .lookup_val is None ,
105+ " query_string" : cl .get_query_string ({}, [self .lookup_kwarg ]),
106+ " display" : _ (" All" ),
101107 }
102108
103109 for pk , title in self .lookup_choices :
104110 yield {
105- ' selected' : pk == int (self .lookup_val or '0' ),
106- ' query_string' : cl .get_query_string ({self .lookup_kwarg : pk }),
107- ' display' : mark_safe (smart_text (title ))
111+ " selected" : pk == int (self .lookup_val or "0" ),
112+ " query_string" : cl .get_query_string ({self .lookup_kwarg : pk }),
113+ " display" : mark_safe (smart_text (title )),
108114 }
109115
110116 def title (self ):
111- return _ (' Category' )
117+ return _ (" Category" )
0 commit comments