禁用“保存”和“保存并继续编辑” Django 管理中模型的按钮
我正在 Django 应用程序中编写模型的管理视图。该管理视图应该是只读视图。我也不希望任何人创建或删除记录。我已设法阻止用户创建和删除记录。这是我模型的管理类:
class EmailAdmin(admin.ModelAdmin):
"""
Admin part for managing the the Email model
"""
list_display = ['to', 'subject', 'ok',]
list_filter = ['ok']
readonly_fields = ['when', 'to', 'subject', 'body', 'ok']
search_fields = ['subject', 'body', 'to']
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
return False
当用户单击管理中的记录时,他会进入详细视图,在该视图中他无法编辑任何内容,因为所有字段都是只读的,但他仍然会在下部看到两个按钮 -管理控制台的右侧显示“保存”和“保存并继续编辑”。是否可以删除这些链接?我想要一个完全只读的管理视图。
谢谢。
I'm writing the admin view for the model in my Django application. This admin view should a be a read-only view. I don't want anyone creating or deleting records either. I've managed to prevent user's from creating and deleting records. Here's my model's admin class:
class EmailAdmin(admin.ModelAdmin):
"""
Admin part for managing the the Email model
"""
list_display = ['to', 'subject', 'ok',]
list_filter = ['ok']
readonly_fields = ['when', 'to', 'subject', 'body', 'ok']
search_fields = ['subject', 'body', 'to']
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
return False
When the user clicks on a record in the admin, it takes him to the detail view where he can't edit anything as all the fields are read-only but he continues to see two buttons on the lower-right hand side of the admin console that read 'Save' and 'Save and continue editing'. Is it possible to remove these links? I'd like to have a total read-only admin view.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论