mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #21428 -- editable GenericRelation regression
The GenericRelation refactoring removed GenericRelations from model._meta.many_to_many. This had the side effect of disallowing editable GenericRelations in ModelForms. Editable GenericRelations aren't officially supported, but if we don't fix this we don't offer any upgrade path for those who used the ability to set editable=True in GenericRelation subclass. Thanks to Trac alias joshcartme for the report and stephencmd and Loic for working on this issue.
This commit is contained in:
parent
b642d540d4
commit
0e079e4331
5 changed files with 35 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
from django.db.models import Q, Sum
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test import TestCase, skipIfDBFeature
|
||||
from django.forms.models import modelform_factory
|
||||
|
||||
from .models import (
|
||||
Address, Place, Restaurant, Link, CharLink, TextLink,
|
||||
|
@ -236,3 +237,13 @@ class GenericRelationTests(TestCase):
|
|||
# Finally test that filtering works.
|
||||
self.assertEqual(qs.filter(links__sum__isnull=True).count(), 1)
|
||||
self.assertEqual(qs.filter(links__sum__isnull=False).count(), 0)
|
||||
|
||||
def test_editable_generic_rel(self):
|
||||
GenericRelationForm = modelform_factory(HasLinkThing, fields='__all__')
|
||||
form = GenericRelationForm()
|
||||
self.assertIn('links', form.fields)
|
||||
form = GenericRelationForm({'links': None})
|
||||
self.assertTrue(form.is_valid())
|
||||
form.save()
|
||||
links = HasLinkThing._meta.get_field_by_name('links')[0].field
|
||||
self.assertEqual(links.save_form_data_calls, 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue