#NEWLINE# def test_treerelatedfieldlistfilter_manytomany( self ) : #NEWLINE# #INDENT# modeladmin = BookAdmin ( Book , site ) #NEWLINE# request = self . request_factory . get ( '/' ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 1 ] #NEWLINE# expected = [ ( self . parent_category . pk , self . parent_category . name , ' style="padding-left:0px"' ) , ( self . child_category1 . pk , self . child_category1 . name , ' style="padding-left:10px"' ) , ( self . child_category2 . pk , self . child_category2 . name , ' style="padding-left:10px"' ) , ( self . simple_category . pk , self . simple_category . name , ' style="padding-left:0px"' ) ] #NEWLINE# self . assertEqual ( sorted ( filterspec . lookup_choices ) , sorted ( expected ) ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'm2m__isnull' : 'True' , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . book4 ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 1 ] #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ ( - 1 ) ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choices [ ( - 1 ) ] [ 'query_string' ] , '?m2m__isnull=True' ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'm2m__id__inhierarchy' : self . parent_category . pk , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . book1 , self . book2 ] ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'm2m__id__inhierarchy' : self . child_category1 . pk , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . book1 ] ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'fk__id__inhierarchy' : self . child_category2 . pk , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( queryset . count ( ) , 0 ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'm2m__id__inhierarchy' : self . simple_category . pk , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . book3 ] )