diff options
| author | sarahboyce <sarahvboyce95@gmail.com> | 2022-09-19 10:44:40 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-09-27 12:55:33 +0200 |
| commit | ae3d575ec3873d87d187783ea706a868aefc33b6 (patch) | |
| tree | ce5a61a6a67926d3f4cc4daa22662c2dc87dd8bc /tests | |
| parent | 67c34c1a3718f6d0a18bd72ca6a9795d9f4ee251 (diff) | |
Added tests for QuerySet.update_or_create() with multi-table inheritance.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/get_or_create/models.py | 4 | ||||
| -rw-r--r-- | tests/get_or_create/tests.py | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/get_or_create/models.py b/tests/get_or_create/models.py index 4b5f081efa..f8f6157348 100644 --- a/tests/get_or_create/models.py +++ b/tests/get_or_create/models.py @@ -50,6 +50,10 @@ class Author(models.Model): name = models.CharField(max_length=100) +class Journalist(Author): + specialty = models.CharField(max_length=100) + + class Book(models.Model): name = models.CharField(max_length=100) authors = models.ManyToManyField(Author, related_name="books") diff --git a/tests/get_or_create/tests.py b/tests/get_or_create/tests.py index a2821187b2..aa68d41c00 100644 --- a/tests/get_or_create/tests.py +++ b/tests/get_or_create/tests.py @@ -12,6 +12,7 @@ from .models import ( Author, Book, DefaultPerson, + Journalist, ManualPrimaryKeyTest, Person, Profile, @@ -503,6 +504,15 @@ class UpdateOrCreateTests(TestCase): ) self.assertFalse(created) + def test_mti_update_non_local_concrete_fields(self): + journalist = Journalist.objects.create(name="Jane", specialty="Politics") + journalist, created = Journalist.objects.update_or_create( + pk=journalist.pk, + defaults={"name": "John"}, + ) + self.assertIs(created, False) + self.assertEqual(journalist.name, "John") + class UpdateOrCreateTestsWithManualPKs(TestCase): def test_create_with_duplicate_primary_key(self): |
