Open ababic opened 8 years ago
Sounds like a good idea.
Some of the cases for customizing the modeladmin that I can think of are:
Thanks for the input @theju.
In regards to custom validation, we at RKH have found that overriding the clean
and save
methods on the model itself is often the most reliable way to achieve such things when working with Wagtail (it works for page-type models, too!). I suppose it depends on what you're trying to achieve, though.
'exclude' behaviour is implemented (as the form_fields_exclude
attribute) as of wagtail/wagtail#3295; leaving this issue open for the remaining proposals ('fields' / 'include_fields', and specifying a panel definition on the ModelAdmin class).
@gasman Hi, Is it possible somehow to exclude fields from form for Page-models depending on some conditions?
Right now I have only 1 solution:
class NewFieldPanel(FieldPanel):
def bind_to_instance(self, instance=None, form=None, request=None):
form.fields['managers'].widget = HiddenInput()
new = super().bind_to_instance(
instance=instance, form=form, request=request
)
return new
Bu it only hides input instead of removing field panel at all. I need somehow override exclude in Meta.
Support for panels
and edit_handler
were added in wagtail/wagtail#4900, so only fields
/include_fields
is remaining.
However, as per wagtail/rfcs#85, I'm transferring this issue to the wagtail-modeladmin repository.
This would be reasonably simple to implement into the
modeladmin
app, but it wouldn't be possible right now to pick those panel definitions up in other views, such as for use inInlinePanel
s etc.Maybe this is a discussion for a separate thread, but maybe if we moved toward a django-like approach, where there'd be a central registry of models and their ModelAdmin classes, so configuration like that could be picked up?
I think it would also be sensible to support
fields
andexclude
attributes (maybe using different names?) on the ModelAdmin class. I know our aim isn't to fully support every feature of Django ModelAdmin, and the line must be drawn somewhere, but to save developers from having to import and a bunch of edit handlers and write full definitions, just to change field order or exclude a couple of fields, I think would be a nice feature.Any thoughts?