mirror of https://github.com/django/django.git
[4.2.x] Fixed #34349 -- Fixed FormSet.empty_form crash when deleting extra forms is disabled.
Backport of 6cbc403b8e
from main
This commit is contained in:
parent
aab25a69dd
commit
bb94e1b7db
|
@ -492,7 +492,9 @@ class BaseFormSet(RenderableFormMixin):
|
|||
required=False,
|
||||
widget=self.get_ordering_widget(),
|
||||
)
|
||||
if self.can_delete and (self.can_delete_extra or index < initial_form_count):
|
||||
if self.can_delete and (
|
||||
self.can_delete_extra or (index is not None and index < initial_form_count)
|
||||
):
|
||||
form.fields[DELETION_FIELD_NAME] = BooleanField(
|
||||
label=_("Delete"),
|
||||
required=False,
|
||||
|
|
|
@ -1482,6 +1482,7 @@ class FormsFormsetTestCase(SimpleTestCase):
|
|||
self.assertIn("DELETE", formset.forms[0].fields)
|
||||
self.assertNotIn("DELETE", formset.forms[1].fields)
|
||||
self.assertNotIn("DELETE", formset.forms[2].fields)
|
||||
self.assertNotIn("DELETE", formset.empty_form.fields)
|
||||
|
||||
formset = ChoiceFormFormset(
|
||||
data={
|
||||
|
|
Loading…
Reference in New Issue