wagtail-nest / wagtail-modeladmin

Add any model in your project to the Wagtail admin. Formerly wagtail.contrib.modeladmin.
Other
21 stars 8 forks source link

Support 'fields' on the ModelAdmin class for non-Page models #6

Open ababic opened 8 years ago

ababic commented 8 years ago

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 in InlinePanels 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 and exclude 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?

theju commented 8 years ago

Sounds like a good idea.

Some of the cases for customizing the modeladmin that I can think of are:

ababic commented 8 years ago

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.

gasman commented 6 years ago

'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).

DzMkh commented 5 years ago

@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.

laymonage commented 1 year ago

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.