<s> from django . db . models import Q <EOL> from django . test import TestCase <EOL> from models import Issue , User <EOL> class RelatedObjectTests ( TestCase ) : <EOL> def test_m2m_and_m2o ( self ) : <EOL> r = User . objects . create ( username = "<STR_LIT>" ) <EOL> g = User . objects . create ( username = "<STR_LIT>" ) <EOL> i1 = Issue ( num = <NUM_LIT:1> ) <EOL> i1 . client = r <EOL> i1 . save ( ) <EOL> i2 = Issue ( num = <NUM_LIT:2> ) <EOL> i2 . client = r <EOL> i2 . save ( ) <EOL> i2 . cc . add ( r ) <EOL> i3 = Issue ( num = <NUM_LIT:3> ) <EOL> i3 . client = g <EOL> i3 . save ( ) <EOL> i3 . cc . add ( r ) <EOL> self . assertQuerysetEqual ( <EOL> Issue . objects . filter ( client = r . id ) , [ <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:2> , <EOL> ] , <EOL> lambda i : i . num <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Issue . objects . filter ( client = g . id ) , [ <EOL> <NUM_LIT:3> , <EOL> ] , <EOL> lambda i : i . num <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Issue . objects . filter ( cc__id__exact = g . id ) , [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Issue . objects . filter ( cc__id__exact = r . id ) , [ <EOL> <NUM_LIT:2> , <EOL> <NUM_LIT:3> , <EOL> ] , <EOL> lambda i : i . num <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Issue . objects . filter ( Q ( cc__id__exact = r . id ) | Q ( client = r . id ) ) , [ <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:2> , <EOL> <NUM_LIT:3> , <EOL> ] , <EOL> lambda i : i . num <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Issue . objects . filter ( cc__id__exact = r . id ) | Issue . objects . filter ( client = r . id ) , [ <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:2> , <EOL> <NUM_LIT:3> , <EOL> ] , <EOL> lambda i : i . num <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Issue . objects . filter ( Q ( client = r . id ) | Q ( cc__id__exact = r . id ) ) , [ <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:2> , <EOL> <NUM_LIT:3> , <EOL> ] , <EOL> lambda i : i . num <EOL> ) </s>
