Validation not invoked in custom admin action

I have a custom admin action that update the queryset of the selected items in the admin list:

# Django 3.2
def custom_action(self,description="Log it"):
    def action_func(modeladmin, request, queryset):
         _task_date = datetime.datetime.strptime(request.POST['task_date'], "%d/%m/%Y")
         queryset.update(task_date=_task_date), "All selected tasks logged successfully")
         emsg = sys.exc_info()[1]

    action_func.short_description = description
    return action_func

The issue is the validation that is implemented with the model “Clean” method is never invoked. Note that when saving/updating one instance of the model the validation is processed correctly.

Thanks in advance.


From the docs on the update method:

Finally, realize that update() does an update at the SQL level and, thus, does not call any save() methods on your models, nor does it emit the pre_save or post_save signals (which are a consequence of calling

If you want the clean method run on all the rows, you need to process them individually and not as a bulk update.

1 Like

Many Thanks @KenWhitesell