美文网首页django admin 这么强还需要写后台页面?
django admin 这么强还需要写后台页面? 2)list

django admin 这么强还需要写后台页面? 2)list

作者: 月球在此 | 来源:发表于2023-12-11 17:04 被阅读0次
WX20231212-165745@2x.png

这里我们正常显示的id写法是

    list_display = ['pk', 'name']
我希望显示成id+产品名称我们应该怎么写 WX20231212-170258@2x.png
from django.contrib import admin
from .models import MyModel

class MyModelAdmin(admin.ModelAdmin):
    list_display = ('custom_field')

    def custom_field(self, obj):
        # 这里可以添加自定义的逻辑来返回你想要显示的值
        return obj.field1 + " - " + obj.field2

    custom_field.short_description = "Custom Field"  # 设置列的标题

相关文章

网友评论

    本文标题:django admin 这么强还需要写后台页面? 2)list

    本文链接:https://www.haomeiwen.com/subject/bptfgdtx.html