mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #17615 -- Corrected unique field validation when using multitable inheritance. The validation used wrong pk value if the parent and child model had different pk fields. Thanks ungenio for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17920 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user