I have a Django Model which I wish to be only readonly. No adds and edits allowed.
I have marked all fields readonly and overridden has_add_permission in ModelAdmin as:
class SomeModelAdmin(admin.ModelAdmin): def has_add_permission(self, request): return False
Is there a similar has_edit_permission
? Which can be disabled to remove "Save" and "Save and continue" buttons? And replace by a simple "Close and Return" button.
Django Documentation Only mentions only about read only fields not about overriding edit permissions.
Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .
The simplest option is to set save_as=True on the ModelAdmin . This will replace the "Save and add another" button with a "Save as new" button.
You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category , the admin displays Categorys , but by adding the Meta class, we can change it to Categories . Save this answer. Show activity on this post.
For Django 1.11:
def has_add_permission(self, request, obj=None): return False def changeform_view(self, request, object_id=None, form_url='', extra_context=None): extra_context = extra_context or {} extra_context['show_save_and_continue'] = False extra_context['show_save'] = False return super(YourModelAdmin, self).changeform_view(request, object_id, extra_context=extra_context)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With