summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/model_inheritance_regress/models.py7
-rw-r--r--tests/regressiontests/model_inheritance_regress/tests.py17
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/regressiontests/model_inheritance_regress/models.py b/tests/regressiontests/model_inheritance_regress/models.py
index bb5d77c51f..161569bcb3 100644
--- a/tests/regressiontests/model_inheritance_regress/models.py
+++ b/tests/regressiontests/model_inheritance_regress/models.py
@@ -163,3 +163,10 @@ class BusStation(Station):
class TrainStation(Station):
zone = models.IntegerField()
+
+class User(models.Model):
+ username = models.CharField(max_length=30, unique=True)
+
+class Profile(User):
+ profile_id = models.AutoField(primary_key=True)
+ extra = models.CharField(max_length=30, blank=True)
diff --git a/tests/regressiontests/model_inheritance_regress/tests.py b/tests/regressiontests/model_inheritance_regress/tests.py
index 8e2c56bd55..3cb6f9d603 100644
--- a/tests/regressiontests/model_inheritance_regress/tests.py
+++ b/tests/regressiontests/model_inheritance_regress/tests.py
@@ -6,6 +6,7 @@ from __future__ import absolute_import
import datetime
from operator import attrgetter
+from django import forms
from django.test import TestCase
@@ -13,7 +14,7 @@ from .models import (Place, Restaurant, ItalianRestaurant, ParkingLot,
ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM,
Person, BirthdayParty, BachelorParty, MessyBachelorParty,
- InternalCertificationAudit, BusStation, TrainStation)
+ InternalCertificationAudit, BusStation, TrainStation, User, Profile)
class ModelInheritanceTest(TestCase):
@@ -408,3 +409,17 @@ class ModelInheritanceTest(TestCase):
)
self.assertIs(BusStation._meta.pk.model, BusStation)
self.assertIs(TrainStation._meta.pk.model, TrainStation)
+
+ def test_inherited_unique_field_with_form(self):
+ """
+ Test that a model which has different primary key for the parent model
+ passes unique field checking correctly. Refs #17615.
+ """
+ class ProfileForm(forms.ModelForm):
+ class Meta:
+ model = Profile
+ User.objects.create(username="user_only")
+ p = Profile.objects.create(username="user_with_profile")
+ form = ProfileForm({'username': "user_with_profile", 'extra': "hello"},
+ instance=p)
+ self.assertTrue(form.is_valid())