Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.4.x] Revert "Fixed #13794 -- Fixed to_field usage in BaseInlineFor…

…mSet."

This reverts commit b445190.

stable/1.4.x branch is in security-fixes-only mode.
  • Loading branch information...
commit aa9c45c2e425662d980cca82974da0986fdbe406 1 parent b445190
@ramiro ramiro authored
View
8 django/forms/models.py
@@ -712,12 +712,8 @@ def _construct_form(self, i, **kwargs):
# Remove the foreign key from the form's data
form.data[form.add_prefix(self.fk.name)] = None
- # Set the fk value here so that the form can do its validation.
- fk_value = self.instance.pk
- if self.fk.rel.field_name != self.fk.rel.to._meta.pk.name:
- fk_value = getattr(self.instance, self.fk.rel.field_name)
- fk_value = getattr(fk_value, 'pk', fk_value)
- setattr(form.instance, self.fk.get_attname(), fk_value)
+ # Set the fk value here so that the form can do it's validation.
+ setattr(form.instance, self.fk.get_attname(), self.instance.pk)
return form
@classmethod
View
9 tests/regressiontests/model_formsets_regress/models.py
@@ -9,15 +9,6 @@ class UserSite(models.Model):
user = models.ForeignKey(User, to_field="username")
data = models.IntegerField()
-class UserProfile(models.Model):
- user = models.ForeignKey(User, unique=True, to_field="username")
- about = models.TextField()
-
-class ProfileNetwork(models.Model):
- profile = models.ForeignKey(UserProfile, to_field="user")
- network = models.IntegerField()
- identifier = models.IntegerField()
-
class Place(models.Model):
name = models.CharField(max_length=50)
View
36 tests/regressiontests/model_formsets_regress/tests.py
@@ -6,10 +6,7 @@
from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory, BaseModelFormSet
from django.test import TestCase
-from .models import (
- User, UserSite, UserProfile, ProfileNetwork, Restaurant, Manager, Network,
- Host,
-)
+from .models import User, UserSite, Restaurant, Manager, Network, Host
class InlineFormsetTests(TestCase):
@@ -156,37 +153,6 @@ def test_formset_over_inherited_model(self):
else:
self.fail('Errors found on formset:%s' % form_set.errors)
- def test_inline_model_with_to_field(self):
- """
- #13794 --- An inline model with a to_field of a formset with instance
- has working relations.
- """
- FormSet = inlineformset_factory(User, UserSite, exclude=('is_superuser',))
-
- user = User.objects.create(username="guido", serial=1337)
- UserSite.objects.create(user=user, data=10)
- formset = FormSet(instance=user)
-
- # Testing the inline model's relation
- self.assertEqual(formset[0].instance.user_id, "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
- formset with instance has working relations.
- """
- FormSet = inlineformset_factory(UserProfile, ProfileNetwork, exclude=[])
-
- user = User.objects.create(username="guido", serial=1337, pk=1)
- self.assertEqual(user.pk, 1)
- profile = UserProfile.objects.create(user=user, about="about", pk=2)
- self.assertEqual(profile.pk, 2)
- ProfileNetwork.objects.create(profile=profile, network=10, identifier=10)
- formset = FormSet(instance=profile)
-
- # Testing the inline model's relation
- self.assertEqual(formset[0].instance.profile_id, 1)
-
def test_formset_with_none_instance(self):
"A formset with instance=None can be created. Regression for #11872"
Form = modelform_factory(User)
Please sign in to comment.
Something went wrong with that request. Please try again.