PolymorphicFormSetChild overrides form exclude
Vayel opened this issue · comments
Vincent Lefoulon commented
Hi!
I have these models:
from django.db import models
from polymorphic.models import PolymorphicModel
class Author(models.Model):
pass
class Book(PolymorphicModel):
author = models.ForeignKey(Author, on_delete=models.CASCADE)
class SpecialBook(Book):
pass
I want to make a formset to edit special books of a given author:
from django import forms
from polymorphic.formsets import polymorphic_modelformset_factory, PolymorphicFormSetChild
class SpecialBookForm(forms.ModelForm):
class Meta:
exclude = ("author",)
SpecialBookFormSet = polymorphic_modelformset_factory(Book, formset_children=(
PolymorphicFormSetChild(SpecialBook, form=SpecialBookForm),
))
By doing so, the field author
is not excluded. Indeed, due to this line, exclude
is not None
when passed to modelform_factory()
here then form.Meta.exclude
is overridden here.
What's the point of self.exclude = exclude or ()
here?
Thanks!
João Antunes commented
Hi! The original maintainer of this project is not longer actively working on it. I don't know enough of the project to be able to answer your question. If you think that's a bug, please feel free to open a PR, and run your changes against the unit tests.