#NEWLINE# def test_annotation_disjunction( self ) : #NEWLINE# #INDENT# qs = Book . objects . annotate ( n_authors = Count ( 'authors' ) ) . filter ( ( Q ( n_authors = 2 ) | Q ( name = 'Python Web Development with Django' ) ) ) #NEWLINE# self . assertQuerysetEqual ( qs , [ 'Artificial Intelligence: A Modern Approach' , 'Python Web Development with Django' , 'The Definitive Guide to Django: Web Development Done Right' ] , attrgetter ( 'name' ) ) #NEWLINE# qs = Book . objects . annotate ( n_authors = Count ( 'authors' ) ) . filter ( ( Q ( name = 'The Definitive Guide to Django: Web Development Done Right' ) | ( Q ( name = 'Artificial Intelligence: A Modern Approach' ) & Q ( n_authors = 3 ) ) ) ) #NEWLINE# self . assertQuerysetEqual ( qs , [ 'The Definitive Guide to Django: Web Development Done Right' ] , attrgetter ( 'name' ) ) #NEWLINE# qs = Publisher . objects . annotate ( rating_sum = Sum ( 'book__rating' ) , book_count = Count ( 'book' ) ) . filter ( ( Q ( rating_sum__gt = 5.5 ) | Q ( rating_sum__isnull = True ) ) ) . order_by ( 'pk' ) #NEWLINE# self . assertQuerysetEqual ( qs , [ 'Apress' , 'Prentice Hall' , "Jonno's House of Books" ] , attrgetter ( 'name' ) ) #NEWLINE# qs = Publisher . objects . annotate ( rating_sum = Sum ( 'book__rating' ) , book_count = Count ( 'book' ) ) . filter ( ( Q ( pk__lt = F ( 'book_count' ) ) | Q ( rating_sum = None ) ) ) . order_by ( 'pk' ) #NEWLINE# self . assertQuerysetEqual ( self , [ 'Apress' , "Jonno's House of Books" ] , attrgetter ( 'name' ) )