In modeladmin, there's a bit of inconsistency in how the views are initialised. There's a distinction between 'Instance specific' views (those that sub-class wagtail.contrib.modeladmin.views.InstanceSpecificView) and the other views.
Really, there's no need for the __init__() method of InstanceSpecificView to be any different to that of WMABaseView (the only important thing for modeladmin views at initialisation is the linking to a ModelAdmin instance). The instance_pk should be provided to dispatch() instead, and dealt with appropriately there. This would give us:
A way to truly 'genericise' the various action_view() methods on the ModelAdmin class (as currently being proposed in wagtail/wagtail-modeladmin#10) without having to add special treatment for certain actions.
Views that are easier to understand, and easier for developers to reuse.
Fetching the object in dispatch would mean we have access toHttpRequest object, so we could reuse ModelAdmin.get_queryset() to get a base queryset from which to search for an instance, rather than just using the default manager's get_queryset() method.
The only thing I'm not sure about is backwards compatibility / deprecation, since we're currently telling people in the docs to copy from current examples to implement custom views... so that's potentially a big issue.
Any input / thoughts from others would be much appreciated.
In modeladmin, there's a bit of inconsistency in how the views are initialised. There's a distinction between 'Instance specific' views (those that sub-class
wagtail.contrib.modeladmin.views.InstanceSpecificView
) and the other views.Really, there's no need for the
__init__()
method of InstanceSpecificView to be any different to that ofWMABaseView
(the only important thing for modeladmin views at initialisation is the linking to a ModelAdmin instance). Theinstance_pk
should be provided todispatch()
instead, and dealt with appropriately there. This would give us:action_view()
methods on theModelAdmin
class (as currently being proposed in wagtail/wagtail-modeladmin#10) without having to add special treatment for certain actions.HttpRequest
object, so we could reuseModelAdmin.get_queryset()
to get a base queryset from which to search for an instance, rather than just using the default manager'sget_queryset()
method.The only thing I'm not sure about is backwards compatibility / deprecation, since we're currently telling people in the docs to copy from current examples to implement custom views... so that's potentially a big issue.
Any input / thoughts from others would be much appreciated.