#NEWLINE# def test_multiple_table( self ) : #NEWLINE# #INDENT# post = Post . objects . create ( title = 'Lorem Ipsum' ) #NEWLINE# post . attached_comment_set . create ( content = 'Save $ on V1agr@' , is_spam = True ) #NEWLINE# post . attached_link_set . create ( content = 'The Web framework for perfections with deadlines.' , url = 'http://www.djangoproject.com/' ) #NEWLINE# self . assertRaises ( AttributeError , getattr , post , 'attached_%(class)s_set' ) #NEWLINE# p1 = Place . objects . create ( name = 'Master Shakes' , address = '666 W. Jersey' ) #NEWLINE# p2 = Place . objects . create ( name = 'Ace Harware' , address = '1013 N. Ashland' ) #NEWLINE# r = Restaurant . objects . create ( name = 'Demon Dogs' , address = '944 W. Fullerton' , serves_hot_dogs = True , serves_pizza = False , rating = 2 ) #NEWLINE# c = Chef . objects . create ( name = 'Albert' ) #NEWLINE# ir = ItalianRestaurant . objects . create ( name = 'Ristorante Miron' , address = '1234 W. Ash' , serves_hot_dogs = False , serves_pizza = False , serves_gnocchi = True , rating = 4 , chef = c ) #NEWLINE# self . assertQuerysetEqual ( ItalianRestaurant . objects . filter ( address = '1234 W. Ash' ) , [ 'Ristorante Miron' ] , attrgetter ( 'name' ) ) #NEWLINE# ir . address = '1234 W. Elm' #NEWLINE# ir . save ( ) #NEWLINE# self . assertQuerysetEqual ( ItalianRestaurant . objects . filter ( address = '1234 W. Elm' ) , [ 'Ristorante Miron' ] , attrgetter ( 'name' ) ) #NEWLINE# self . assertEqual ( [ f . name for f in Restaurant . _meta . fields ] , [ 'id' , 'name' , 'address' , 'place_ptr' , 'rating' , 'serves_hot_dogs' , 'serves_pizza' , 'chef' ] ) #NEWLINE# self . assertEqual ( [ f . name for f in ItalianRestaurant . _meta . fields ] , [ 'id' , 'name' , 'address' , 'place_ptr' , 'rating' , 'serves_hot_dogs' , 'serves_pizza' , 'chef' , 'restaurant_ptr' , 'serves_gnocchi' ] ) #NEWLINE# self . assertEqual ( Restaurant . _meta . ordering , [ '-rating' ] ) #NEWLINE# self . assertQuerysetEqual ( Place . objects . filter ( supplier__name = 'foo' ) , [ ] ) #NEWLINE# self . assertRaises ( FieldError , Restaurant . objects . filter , supplier__name = 'foo' ) #NEWLINE# self . assertQuerysetEqual ( Restaurant . objects . filter ( name = 'Demon Dogs' ) , [ 'Demon Dogs' ] , attrgetter ( 'name' ) ) #NEWLINE# self . assertQuerysetEqual ( ItalianRestaurant . objects . filter ( address = '1234 W. Elm' ) , [ 'Ristorante Miron' ] , attrgetter ( 'name' ) ) #NEWLINE# p = Place . objects . get ( name = 'Demon Dogs' ) #NEWLINE# self . assertIs ( type ( p ) , Place ) #NEWLINE# self . assertEqual ( p . restaurant , Restaurant . objects . get ( name = 'Demon Dogs' ) ) #NEWLINE# self . assertEqual ( Place . objects . get ( name = 'Ristorante Miron' ) . restaurant . italianrestaurant , ItalianRestaurant . objects . get ( name = 'Ristorante Miron' ) ) #NEWLINE# self . assertEqual ( Restaurant . objects . get ( name = 'Ristorante Miron' ) . italianrestaurant , ItalianRestaurant . objects . get ( name = 'Ristorante Miron' ) ) #NEWLINE# self . assertRaises ( ItalianRestaurant . DoesNotExist , ( lambda : p . restaurant . italianrestaurant ) ) #NEWLINE# self . assertRaises ( Place . DoesNotExist , ItalianRestaurant . objects . get , name = 'The Noodle Void' ) #NEWLINE# self . assertRaises ( Place . MultipleObjectsReturned , Restaurant . objects . get , id__lt = 12321 ) #NEWLINE# s1 = Supplier . objects . create ( name = "Joe's Chickens" , address = '123 Sesame St' ) #NEWLINE# s1 . customers = [ r , ir ] #NEWLINE# s2 = Supplier . objects . create ( name = "Luigi's Pasta" , address = '456 Sesame St' ) #NEWLINE# s2 . customers = [ ir ] #NEWLINE# p = Place . objects . get ( name = "Joe's Chickens" ) #NEWLINE# self . assertRaises ( Restaurant . DoesNotExist , ( lambda : p . restaurant ) ) #NEWLINE# self . assertEqual ( p . supplier , s1 ) #NEWLINE# self . assertQuerysetEqual ( ir . provider . order_by ( '-name' ) , [ "Luigi's Pasta" , "Joe's Chickens" ] , attrgetter ( 'name' ) ) #NEWLINE# self . assertQuerysetEqual ( Restaurant . objects . filter ( provider__name__contains = 'Chickens' ) , [ 'Ristorante Miron' , 'Demon Dogs' ] , attrgetter ( 'name' ) ) #NEWLINE# self . assertQuerysetEqual ( ItalianRestaurant . objects . filter ( provider__name__contains = 'Chickens' ) , [ 'Ristorante Miron' ] , attrgetter ( 'name' ) ) #NEWLINE# park1 = ParkingLot . objects . create ( name = 'Main St' , address = '111 Main St' , main_site = s1 ) #NEWLINE# park2 = ParkingLot . objects . create ( name = 'Well Lit' , address = '124 Sesame St' , main_site = ir ) #NEWLINE# self . assertEqual ( Restaurant . objects . get ( lot__name = 'Well Lit' ) . name , 'Ristorante Miron' ) #NEWLINE# rows = Restaurant . objects . filter ( serves_hot_dogs = True , name__contains = 'D' ) . update ( name = 'Demon Puppies' , serves_hot_dogs = False ) #NEWLINE# self . assertEqual ( rows , 1 ) #NEWLINE# r1 = Restaurant . objects . get ( pk = r . pk ) #NEWLINE# self . assertFalse ( r1 . serves_hot_dogs ) #NEWLINE# self . assertEqual ( r1 . name , 'Demon Puppies' ) #NEWLINE# self . assertQuerysetEqual ( ItalianRestaurant . objects . values ( 'name' , 'rating' ) , [ { #NEWLINE# #INDENT# 'rating' : 4 , #NEWLINE# 'name' : 'Ristorante Miron' , #NEWLINE# #UNINDENT# } ] , ( lambda o : o ) ) #NEWLINE# self . assertNumQueries ( 2 , ( lambda : ItalianRestaurant . objects . all ( ) [ 0 ] . chef ) ) #NEWLINE# self . assertNumQueries ( 1 , ( lambda : ItalianRestaurant . objects . select_related ( 'chef' ) [ 0 ] . chef ) )