Fixed #29981 -- Fixed inline formsets with a OnetoOneField primary key that uses to_field.

This commit is contained in:
Patrik Sletmo 2018-12-11 20:41:21 +01:00 committed by Tim Graham
parent 02c07be95c
commit 14e2b1b065
3 changed files with 25 additions and 4 deletions

View file

@ -8,8 +8,8 @@ from django.forms.utils import ErrorDict, ErrorList
from django.test import TestCase
from .models import (
Host, Manager, Network, ProfileNetwork, Restaurant, User, UserProfile,
UserSite,
Host, Manager, Network, ProfileNetwork, Restaurant, User, UserPreferences,
UserProfile, UserSite,
)
@ -171,6 +171,14 @@ class InlineFormsetTests(TestCase):
# Testing the inline model's relation
self.assertEqual(formset[0].instance.user_id, "guido")
def test_inline_model_with_primary_to_field(self):
"""An inline model with a OneToOneField with to_field & primary key."""
FormSet = inlineformset_factory(User, UserPreferences, exclude=('is_superuser',))
user = User.objects.create(username='guido', serial=1337)
UserPreferences.objects.create(user=user, favorite_number=10)
formset = FormSet(instance=user)
self.assertEqual(formset[0].fields['user'].initial, 'guido')
def test_inline_model_with_to_field_to_rel(self):
"""
#13794 --- An inline model with a to_field to a related field of a