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

Add bulk actions support for ModelAdmin listings #8

Open
andreasnuesslein opened this issue Jun 16, 2016 · 20 comments
Open

Add bulk actions support for ModelAdmin listings #8

andreasnuesslein opened this issue Jun 16, 2016 · 20 comments
Labels
type:Enhancement New feature or request

Comments

@andreasnuesslein
Copy link

andreasnuesslein commented Jun 16, 2016

Hey Torchies,

we are trying your new ModelAdmin-feature and realized there is no "I'm selecting a bunch of objects and I'm gonna < delete/export/dosomething > them all". Django Admin:
image

So we were wondering: Are you planning on implementing this? If so, do you know when that might be the case? :)

Thanks a bunch

PS: Great job on the ModelAdmin and Wagtail in general

@andreasnuesslein andreasnuesslein changed the title modeladmin select multiple for mass-action ModelAdmin: select multiple for mass-action Jun 16, 2016
@ababic
Copy link

ababic commented Jun 16, 2016

Hi @nutztherookie! Thanks a lot for the feedback :)

I'd certainly love to see something that replicated Django ModelAdmin's 'actions' in the future, but there are no set plans to tackle that right away. I guess we have some thinking/decision-making to do, in regards to how this app evolves and becomes more integrated into the wagtail core (and what things in core need to also change, in order for that to happen)

When modeladmin was still in it's infancy (as wagtailmodeladmin), I made an attempt to add an 'actions-like' feature. But at the time, I stumbled when it came to handling permissions, and ensuring only users with the right actions could perform them. I think it was particularly complicated because of the way pages have their own tree-based permission system, and I decided it was a little too complicated to tackle on my own. Hopefully now, with a keen group of wagtail contributors behind it, that's something that might be overcome.

@gasman gasman added the type:Enhancement New feature or request label Jun 16, 2016
@andreasnuesslein
Copy link
Author

Hey @ababic, thank you for your elaborate answer =)

I know little of wagtails permissions-setup; but also I don't really need it for my project.
I'm gonna start hacking 'actions' into wagtail and I'll see where it leads me. If it turns out to be somewhat mature I'll try and upstream it :)

@SalahAdDin
Copy link

But, if we'll have this features, django-admin will be 'deprecated'. So, for now we can used django-adminnormally.

@ababic
Copy link

ababic commented Jun 24, 2016

@SalahAdDin I'm afraid I'm struggling to understand what you mean there. Are you suggesting that this feature should or shouldn't be implemented? What do you mean when you say django admin will be 'deprecated'? I'm pretty sure django admin isn't going anywhere. It's a fundamental part of django.

@SalahAdDin
Copy link

Ok, i say, for our use, with wagtail-adminand model-admin, for us, will be deprecated because, for what have django-admin if wagtail-admin do all?

@ababic
Copy link

ababic commented Jun 24, 2016

Sorry @SalahAdDin, I don't know what you're asking. Nobody is planning to make any changes that would prevent you running django-admin and wagtailadmin for the same project if you wanted to. Having a feature like this would obviously give developers less need to do that though, which can only be a good thing.

@tomdyson
Copy link

Hi @nutztherookie did you get anywhere with 'actions'? A few other people have asked about this recently.

@andreasnuesslein
Copy link
Author

hey @tomdyson, no sorry - i got derailed and ended up working on other things of the project.

i'd still like to work on it, but don't know when that might be.

@MechanisM
Copy link

Any moves forward on this? I need this one too.

@grwhumphries
Copy link

Just pinging this forward - has there been any implementation of this for Wagtail yet? It can be done in the standard django-admin, so not the end of the world, but it would be really nice to have the option in Wagtail as well.

@devRawnie
Copy link

Re-visiting this in 2021. Would love such a feature, with the option to define actions in a subclass of ModelAdmin class, and apply those to multiple instances.

@SidSidSid16
Copy link

Having the ability to perform mass actions on multiple instances would make things so much easier. Would love an update on this.

@lb-
Copy link
Member

lb- commented Apr 3, 2022

Now that bulk actions exist as of 2.15 I will rename this to be add bulk actions to ModelAdmin

@lb- lb- changed the title ModelAdmin: select multiple for mass-action Add bulk actions support for ModelAdmin listings Apr 3, 2022
@lb-
Copy link
Member

lb- commented Jun 3, 2023

@alittle-ninja there are no plans in place for this on the core roadmap at this time but anyone is welcome to prepare are PR for this feature.

@ababic
Copy link

ababic commented Jun 3, 2023

On the topic of new features for modeladmin, I think we need to be careful how we tread, as there are rough plans to sunset that module completely (I'd hate for someone to go to all the effort of contributing and polishing, only for the work never to be merged).

The plan isn't entirely clear, but from the conversations I've had with @laymonage, it looks something like this:

  1. Continue to bring snippets functionality in-line with ModelAdmin (under way).
  2. Ensure things are designed in such a way that most of the views and features from snippets are available on generic sets of views (of which, 'snippets' will be one opinionated 'flavour').
  3. Figure out what the registration mechanisms look like for non-snippet models.
  4. After a standard deprecation period (long enough for devs to translate old modeladmin code over to the new), either remove the modeladmin app completely, or move it out to it's own third-party app to die a bit more slowly 😜

@laymonage please do let me know if this summary is inaccurate. It's been a while since we discussed this!

@laymonage
Copy link
Collaborator

The summary posted by @ababic above is accurate.

In regards to bulk actions, I think it could use some refactoring internally before we start expanding it, as the approach is not ideal in some places, e.g. how the strings are set up for the client-side interface: https://github.com/wagtail/wagtail/blob/a6a91e1a014912c6f7f65cc367c099e9338c8906/wagtail/admin/localization.py#L58-L95

Anyway, as per wagtail/rfcs#85, I'm transferring this issue over to the wagtail-modeladmin repo.

@laymonage laymonage transferred this issue from wagtail/wagtail Jul 26, 2023
@TonisPiip
Copy link

https://docs.wagtail.org/en/stable/extending/custom_bulk_actions.html#custom-bulk-actions

docs for how to get it working in wagtail for lost souls

@Morsey187
Copy link

Morsey187 commented Dec 18, 2023

I recently explored implementing bulk actions within a ModelViewSet and achieved this functionality in this commit Morsey187/wagtail-defender@a24e346.

Screenshot
Screenshot 2023-12-18 at 21 19 49

Although this approach might become incompatible with future releases due to bulk actions potentially being refactored as mentioned in the previous comments, it does currently function well and doesn't require overriding too much code. So thought I'd share incase it's helpful to anyone looking for a similar approach with Wagtail 5.2 and are migrating from ModelAdmin to ModelViewset.

@laymonage
Copy link
Collaborator

I recently explored implementing bulk actions within a ModelViewSet and achieved this functionality in this commit Morsey187/wagtail-defender@a24e346.

Screenshot
Screenshot 2023-12-18 at 21 19 49

Thanks @Morsey187, that is very helpful! I'm glad that it is possible to integrate bulk actions with ModelViewSet.

I think the only bit I can definitely say for the moment is that the get_columns method will be removed in favour of making the columns a cached property: wagtail/wagtail@a2b5bae

I think the same can be done in your custom code. Or, alternatively I think it's possible to use list_display to achieve this, e.g.

class MyModelViewSet(ModelViewSet)
    list_display = [BulkActionsCheckboxColumn("bulk_actions"),
            *ModelViewSet.index_view_class.columns]

Which would eliminate the need to override the index view class.

Although this approach might become incompatible with future releases due to bulk actions potentially being refactored as mentioned in the previous comments, it does currently function well and doesn't require overriding too much code. So thought I'd share incase it's helpful to anyone looking for a similar approach with Wagtail 5.2 and are migrating from ModelAdmin to ModelViewset.

Yeah the bulk actions system is kind of like its own thing at the moment. Not quite sure what kind of refactoring will be done to it, though it's likely we won't be doing anything drastic in the near future as that would likely break existing setups.

Thank you again for sharing your work! I think we might be able to make this built-in to ModelViewSet in the future, which would also minimise the gap between it and SnippetViewSet.

@Morsey187
Copy link

Thanks @laymonage,
Let me know if I can help with that, I'll follow up with anything in that new issue thread you created.

Just to note:

I think the same can be done in your custom code. Or, alternatively I think it's possible to use list_display to achieve this, e.g.

I think there was an issue with using list_display, as you'll still need to update the IndexView's get_columns method to handle the bulk actions column along with the title field (_get_title_column()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

14 participants