Django Admin - Prevents objects from being saved and does not display a user confirmation message

I want administrators not to modify certain data in django. I did this, but when the user clicks โ€œsaveโ€, the data is not saved correctly, but the message โ€œsuccessโ€ is displayed at the top, telling the user that the data has been updated. How can I replace this message?

thanks

+4
source share
2 answers

I think you want to use a message structure.

In the admin action:

class FooAdmin(admin.ModelAdmin): .... def foo_action(self, request, queryset): .... self.message_user(request, "%s foo objects were not saved" % foos_not_saved) 

In shape (model):

 def save(*args, **kwargs): # do stuff self.message_user(request, "%s fields were not saved" % ','.join(fields_not_saved)) 
+1
source

I believe the message is just js. Javascript for the admin site lives in djangoX.X/django/contrib/admin/media/js/ and I believe you can change the message in actions.js .

Alternatively, you can go to djangoX.X/django/contrib/admin/templates/admin/ and move js from there.

0
source

All Articles