我想隐藏Django管理工具中外键字段的编辑,添加和删除图标。
有可能实现这一目标吗?如果是这样,怎么办?
到目前为止,这是我的代码:
@admin.register(Request)
class RequestAdmin(admin.ModelAdmin):
list_display = (
"name",
"contact_method",
"neighborhood",
"adults",
"children",
"prescriptions",
"volunteer",
"status",
"due_date",
)
list_editable = ("status", "volunteer")
def neighborhood(self, obj):
if obj.address and obj.address.get("neighborhood", False):
neighborhood = obj.address["neighborhood"]
if obj.address.get("details", False):
return f"{neighborhood} - {obj.address['details']}"
return neighborhood
It seems the problem is that I have also registered another model Volunteer
.
@admin.register(Volunteer)
class VolunteerAdmin(admin.ModelAdmin):
list_display = ("name", "contact_method", "neighborhood", "valid_ID")
def neighborhood(self, obj):
if obj.address and obj.address.get("neighborhood", False):
return obj.address["neighborhood"]
但是,我也需要保留此模型。那么,我该如何实现呢?
I was able to hide this icons by using custom CSS for
RequestAdmin
by specifying the file in an internal class Media:The content of
volunteering/static/volunteering/css/style.css
is the following:该应用的结构如下:
现在是这样显示表格的: