Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PolymorphicFormSetChild overrides form exclude #578

Open
Vayel opened this issue Feb 13, 2024 · 1 comment
Open

PolymorphicFormSetChild overrides form exclude #578

Vayel opened this issue Feb 13, 2024 · 1 comment

Comments

@Vayel
Copy link
Contributor

Vayel commented Feb 13, 2024

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!

@j-antunes
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants