您可以调整该字段的大小以使其变小,而不是做一个按钮。
class PurchaseAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CharField: {'widget': TextInput(attrs={'size':'20'})},
models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':40})},
}
admin.site.register(PurchaseOrder, PurchaseAdmin)
如果你真的想要另一个按钮,你可以使用你的自定义 Inline 类来定义字段:
class CustomInline(admin.TabularInline):
readonly_fields = [...'link',...]
# important part which define what "link" looks like
def link(self, instance):
url = # your link to display the note
return mark_safe(u'<a href="{u}">View Note</a>".format(u=url))
在您的自定义管理类中,请改用这个内联类:
class PurchaseAdmin(admin.ModelAdmin):
inlines = [CustomInline]