I am writing a custom action for django admin. This action should only work for records having particular state.
For example “Approve Blog” custom action should approve user blog only when blog is not approved. And it must not appove rejected blogs.
One option is to filter non approved blogs and then approve them. But there are still chances that rejected blogs can be approved.
If user try to approve rejected blog, custom action should notify user about invalid operation in the django admin.
Any solution?
The documentation on admin actions is quite helpful, so go take a look!
I think just writing an action that only updates non-rejected blogs ought to do.
The following code assumes you’ve got variables
rejectedandapprovedthat map to the integral values representing Blogs that have been rejected, and blogs that have been approved respectively: