#35820: Non-editable error for a GenericForeignKey in an ModelForm when
updating to
version 5.1
-------------------------------+--------------------------------------
Reporter: Arthur Hanson | Owner: (none)
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Sarah Boyce):
* resolution: => invalid
* status: new => closed
Comment:
This works fine for me
{{{#!diff
+class TaggedItemWithContentObjectForm(forms.ModelForm):
+ content_object = forms.CharField(max_length=10)
+
+ class Meta:
+ model = TaggedItem
+ fields = ["tag", "content_type", "object_id"]
+
+ def clean(self):
+ # Ignore content_object.
+ self.cleaned_data.pop("content_object")
+ return self.cleaned_data
+
+
class GenericInlineFormsetTests(TestCase):
def test_output(self):
GenericFormSet = generic_inlineformset_factory(TaggedItem,
extra=1)
@@ -217,6 +230,18 @@ class GenericInlineFormsetTests(TestCase):
with self.assertRaisesMessage(Exception, msg):
generic_inlineformset_factory(BadModel, TaggedItemForm)
+ def test_gfk_form(self):
+ quartz = Mineral.objects.create(name="Quartz", hardness=7)
+ ctype = ContentType.objects.get_for_model(quartz)
+ data = {
+ "tag": "lizard",
+ "content_type": ctype.pk,
+ "object_id": quartz.pk,
+ "content_object": "ignored",
+ }
+ form = TaggedItemWithContentObjectForm(data=data)
+ self.assertEqual(form.is_valid(), True)
+
def test_save_new_uses_form_save(self):
}}}
I get an error if I add `content_object` to fields which you don't need to
do
--
Ticket URL: <https://code.djangoproject.com/ticket/35820#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701926b2c4b50-c3524521-4e21-4b6f-b294-dafde86b394b-000000%40eu-central-1.amazonses.com.