Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/query/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Person(models.Model):
name = models.CharField(max_length=20)
surname = models.CharField(max_length=20)
age = models.IntegerField(null=True, blank=True)
another_age = models.IntegerField(null=True, blank=True, db_column='age2')

class Meta:
unique_together = ("name", "surname")
Expand Down
11 changes: 11 additions & 0 deletions tests/query/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@ def test_update_with_F(self):
Person.objects.filter(name='john').update(age=F('age')-10)
self.assertEqual(Person.objects.get(name='john').age, 39)

def test_update_with_F_and_db_column(self):
# This test is simmilar to test_update_with_F but tests
# the update with a column that has a db_column set.
john = Person.objects.create(name='john', surname='nhoj', another_age=42)
andy = Person.objects.create(name='andy', surname='ydna', another_age=-5)
Person.objects.update(another_age=F('another_age')+7)
self.assertEqual(Person.objects.get(pk=john.id).another_age, 49)
self.assertEqual(Person.objects.get(id=andy.pk).another_age, 2)
Person.objects.filter(name='john').update(another_age=F('another_age')-10)
self.assertEqual(Person.objects.get(name='john').another_age, 39)

def test_invalid_update_with_F(self):
self.assertRaises(AssertionError, Person.objects.update, age=F('name')+1)

Expand Down