Admin Issues Setting Perspective Overview Customizations External apps Admin Next
Custom class list filters
c l a s s AdvancedDecadeBornListFilter ( django . c o n t r i b . admin . S i m p l e L i s t F i l t e r ) :
def lookups ( s e l f , request , model admin ) :
”””
Only show the lookups i f t h e r e a c t u a l l y i s
anyone born i n the c o r r e s p o n d i n g decades .
”””
qs = model admin . q u e r y s e t ( r e q u e s t )
i f qs . f i l t e r ( b i r t h d a y g t e=date (1980 , 1 , 1) ,
b i r t h d a y l t e=date (1989 , 12 , 3 1 ) ) . e x i s t s ( ) :
y i e l d ( ’ 80 s ’ , ( ’ i n the e i g h t i e s ’ ))
i f qs . f i l t e r ( b i r t h d a y g t e=date (1990 , 1 , 1) ,
b i r t h d a y l t e=date (1999 , 12 , 3 1 ) ) . e x i s t s ( ) :
y i e l d ( ’ 90 s ’ , ( ’ i n the n i n e t i e s ’ ))
def q u e r y s e t ( s e l f , request , q u e r y s e t ) :