Displaying ForeignKey data in Django admin change/add page

前端 未结 1 1317
自闭症患者
自闭症患者 2021-01-05 04:40

I\'m trying to get an attribute of a model to show up in the Django admin change/add page of another model. Here are my models:

class Download(model.Model):
         


        
相关标签:
1条回答
  • 2021-01-05 05:16

    If you don't need to edit it, you can display it as a readonly field:

    class DownloadAdmin(admin.ModelAdmin):
        readonly_fields = ('task_added_at',)
    
        def task_added_at(self, obj):
            return obj.task.added_at
    
    0 讨论(0)
提交回复
热议问题