File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class Person(models.Model):
2525 name = models .CharField (max_length = 20 )
2626 surname = models .CharField (max_length = 20 )
2727 age = models .IntegerField (null = True , blank = True )
28+ another_age = models .IntegerField (null = True , blank = True , db_column = 'age2' )
2829
2930 class Meta :
3031 unique_together = ("name" , "surname" )
Original file line number Diff line number Diff line change @@ -375,6 +375,17 @@ def test_update_with_F(self):
375375 Person .objects .filter (name = 'john' ).update (age = F ('age' )- 10 )
376376 self .assertEqual (Person .objects .get (name = 'john' ).age , 39 )
377377
378+ def test_update_with_F_and_db_column (self ):
379+ # This test is simmilar to test_update_with_F but tests
380+ # the update with a column that has a db_column set.
381+ john = Person .objects .create (name = 'john' , surname = 'nhoj' , another_age = 42 )
382+ andy = Person .objects .create (name = 'andy' , surname = 'ydna' , another_age = - 5 )
383+ Person .objects .update (another_age = F ('another_age' )+ 7 )
384+ self .assertEqual (Person .objects .get (pk = john .id ).another_age , 49 )
385+ self .assertEqual (Person .objects .get (id = andy .pk ).another_age , 2 )
386+ Person .objects .filter (name = 'john' ).update (another_age = F ('another_age' )- 10 )
387+ self .assertEqual (Person .objects .get (name = 'john' ).another_age , 39 )
388+
378389 def test_invalid_update_with_F (self ):
379390 self .assertRaises (AssertionError , Person .objects .update , age = F ('name' )+ 1 )
380391
You can’t perform that action at this time.
0 commit comments