#NEWLINE# def test_translations( self ) : #NEWLINE# #INDENT# activate ( 'fi' ) #NEWLINE# a1 = Article . objects . create ( pub_date = datetime . date . today ( ) ) #NEWLINE# at1_fi = ArticleTranslation ( article = a1 , lang = 'fi' , title = 'Otsikko' , body = 'Diipadaapa' ) #NEWLINE# at1_fi . save ( ) #NEWLINE# at2_en = ArticleTranslation ( article = a1 , lang = 'en' , title = 'Title' , body = 'Lalalalala' ) #NEWLINE# at2_en . save ( ) #NEWLINE# with self . assertNumQueries ( 1 ) : #NEWLINE# #INDENT# fetched = Article . objects . select_related ( 'active_translation' ) . get ( active_translation__title = 'Otsikko' ) #NEWLINE# self . assertTrue ( ( fetched . active_translation . title == 'Otsikko' ) ) #NEWLINE# #UNINDENT# a2 = Article . objects . create ( pub_date = datetime . date . today ( ) ) #NEWLINE# at2_fi = ArticleTranslation ( article = a2 , lang = 'fi' , title = 'Atsikko' , body = 'Diipadaapa' , abstract = 'dipad' ) #NEWLINE# at2_fi . save ( ) #NEWLINE# a3 = Article . objects . create ( pub_date = datetime . date . today ( ) ) #NEWLINE# at3_en = ArticleTranslation ( article = a3 , lang = 'en' , title = 'A title' , body = 'lalalalala' , abstract = 'lala' ) #NEWLINE# at3_en . save ( ) #NEWLINE# a3 = Article ( id = a3 . id , pub_date = a3 . pub_date , active_translation = at3_en ) #NEWLINE# a3 . save ( ) #NEWLINE# self . assertEqual ( list ( Article . objects . filter ( active_translation__abstract = None ) ) , [ a1 , a3 ] ) #NEWLINE# self . assertEqual ( list ( Article . objects . filter ( active_translation__abstract = None , active_translation__pk__isnull = False ) ) , [ a1 ] ) #NEWLINE# activate ( 'en' ) #NEWLINE# self . assertEqual ( list ( Article . objects . filter ( active_translation__abstract = None ) ) , [ a1 , a2 ] )