diff --git a/django/forms/models.py b/django/forms/models.py
index 8accd61..a229dd6 100644
a
|
b
|
class BaseInlineFormSet(BaseModelFormSet):
|
716 | 716 | |
717 | 717 | # Remove the foreign key from the form's data |
718 | 718 | form.data[form.add_prefix(self.fk.name)] = None |
719 | | |
720 | | # Set the fk value here so that the form can do it's validation. |
721 | | setattr(form.instance, self.fk.get_attname(), self.instance.pk) |
722 | 719 | return form |
723 | 720 | |
724 | 721 | #@classmethod |
diff --git a/tests/regressiontests/model_formsets_regress/tests.py b/tests/regressiontests/model_formsets_regress/tests.py
index 61bc514..73228a5 100644
a
|
b
|
class InlineFormsetTests(TestCase):
|
156 | 156 | # you can create a formset with an instance of None |
157 | 157 | form = Form(instance=None) |
158 | 158 | formset = FormSet(instance=None) |
| 159 | |
| 160 | def test_inline_model_with_to_field(self): |
| 161 | "An inline model with a to_field of a formset with instance have working relations. Regression for #13794" |
| 162 | FormSet = inlineformset_factory(User, UserSite) |
| 163 | |
| 164 | user = User.objects.create(username="guido", serial=1337) |
| 165 | UserSite.objects.create(user=user, data=10) |
| 166 | formset = FormSet(instance=user) |
| 167 | |
| 168 | original_site1 = formset.get_queryset()[0] |
| 169 | |
| 170 | # Testing the inline model's relation |
| 171 | self.assertEqual(original_site1.user.username, "guido") |