-
Notifications
You must be signed in to change notification settings - Fork 8
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
ModelAdmin form_fields_exclude is ignored on models with a panels definition #14
Comments
It's actually a rare use case I think, since you already have custom panels defined, but I guess you want to customise the panels per view. You can also do this by creating multiple edit handlers, but this way should technically also be possible. I'll see if I can add the functionality for this. |
Hi guys. This feature wasn't ever meant to be used in combination with a panels attribute on the model. It's really meant to serve as a shortcut to removing a field or two from the admin form when needed (which shows all editable fields by default), without having to define If the decision has been made to now prefer For consistency, I would propose that the changes in wagtail/wagtail#4363 be reverted, and instead we document that the In a perfect world, we'd have a lot more flexibility baked into |
@lucasmoeskops / @mixxorz please see my comment above. |
tbh I just thought the documentation for That being said, I don't see the point in reverting wagtail/wagtail#4363 because covering one common use-case is better than nothing. The inconsistency can be mitigated, for now at least, by documenting what does and doesn't work. Hopefully, we'll eventually have a solution that fits all use-cases. |
I have to politely disagree here. I think consistency should be of more importance to a project like wagtail, and consistency with model representation is something we need to be improving in wagtail (not the opposite). I know the changes solve a problem in your case, but I do believe the way you're using those two things in combination is rare. A better approach to solving this problem would be to add a
This would allow you to customise both the interface for 'create', 'edit' or any custom views in one place, without having to resort to overriding views. |
I think you bring up valid points. So to summarize:
Does this sound good? If so, I'm willing to open a PR that implements this behavior. By the way, I agree that once we've implemented a "right way" to customize a ModelAdmin's panels, that should override |
Thanks @mixxorz, It may be better to await confirmation from a core team member (@BertrandBordage / @gasman), as they could have different ideas, but that's the approach I would suggest (with 'improving the documentation' for
EDIT: The new method on the |
Sorry for missing this discussion earlier. This is now something we need to resolve for the 2.1 final release, since the current merged version of wagtail/wagtail#4363 has broken the behaviour of It looks to me like the immediate bug is a simple logical error that can be fixed by reverting or adjusting c83a712d5926fbc148c8606bbc4eac7513d9ff0b - I guess the intent of the Instead, I think there's a strong argument that the old behaviour - an explicit panel definition takes priority over So, if there are no strong objections from @BertrandBordage / @lucasmoeskops, I propose reverting wagtail/wagtail#4363 in its entirety. If anyone's able to write a documentation patch in the next week or so to clarify the |
Hi, Thanks for the suggestions. I agree with the point from Matt and ababic that form_fields_exclude was not meant for this and am for reverting it. Optionally it could generate a warning maybe, saying that the form_fields_exclude option was ignored because of the panel definition. |
Now reverted in e84b4a0 (master) / 6ccd665 (stable/2.1.x). |
I believe the same issue/lack of documentation also exists in snippets. That said, this issue thread has been specific to ModelAdmin so I'm transferring this to the wagtail-modeladmin repository as per wagtail/rfcs#85. I'll raise a separate issue for Wagtail's snippets later. |
Maybe the form field exclude behaviour is the cause/confusion underlying this issue. wagtail/wagtail#10625 |
Issue Summary
According to the docs and PR wagtail/wagtail#3295, you should be able to add
form_fields_exclude
orget_form_fields_exclude
on aModelAdmin
to exclude certain fields from rendering on the admin. When I tried it, it didn't work. Upon further investigation, I found out that it has never actually worked. Issue #6 is still open.The issue is rooted in
extract_panel_definitions_from_model_class
function. When you have a model that haspanels
, it returns the panels as is, without filtering the excluded fields.So a couple things that stand out to me:
Steps to Reproduce
ModelAdmin
inwagtail_hooks.py
form_fields_exclude = ['some_field']
as a class attributesome_field
Workaround
I'm currently working around the issue by creating a custom
CreateView
for myModelAdmin
s and overridingget_edit_handlers
to remove panels I don't want.Only problem is this doesn't work for panels without field names. But in my particular case that's okay.
Technical details
The text was updated successfully, but these errors were encountered: