<bdo id='Rq5di'></bdo><ul id='Rq5di'></ul>
  • <i id='Rq5di'><tr id='Rq5di'><dt id='Rq5di'><q id='Rq5di'><span id='Rq5di'><b id='Rq5di'><form id='Rq5di'><ins id='Rq5di'></ins><ul id='Rq5di'></ul><sub id='Rq5di'></sub></form><legend id='Rq5di'></legend><bdo id='Rq5di'><pre id='Rq5di'><center id='Rq5di'></center></pre></bdo></b><th id='Rq5di'></th></span></q></dt></tr></i><div id='Rq5di'><tfoot id='Rq5di'></tfoot><dl id='Rq5di'><fieldset id='Rq5di'></fieldset></dl></div>

      1. <legend id='Rq5di'><style id='Rq5di'><dir id='Rq5di'><q id='Rq5di'></q></dir></style></legend>

        <small id='Rq5di'></small><noframes id='Rq5di'>

        <tfoot id='Rq5di'></tfoot>
      2. 在 Django 管理更改/添加页面中显示 ForeignKey 数据

        时间:2023-11-07

            <bdo id='HwunC'></bdo><ul id='HwunC'></ul>

            <small id='HwunC'></small><noframes id='HwunC'>

              <tbody id='HwunC'></tbody>

              <legend id='HwunC'><style id='HwunC'><dir id='HwunC'><q id='HwunC'></q></dir></style></legend>
              <i id='HwunC'><tr id='HwunC'><dt id='HwunC'><q id='HwunC'><span id='HwunC'><b id='HwunC'><form id='HwunC'><ins id='HwunC'></ins><ul id='HwunC'></ul><sub id='HwunC'></sub></form><legend id='HwunC'></legend><bdo id='HwunC'><pre id='HwunC'><center id='HwunC'></center></pre></bdo></b><th id='HwunC'></th></span></q></dt></tr></i><div id='HwunC'><tfoot id='HwunC'></tfoot><dl id='HwunC'><fieldset id='HwunC'></fieldset></dl></div>
            • <tfoot id='HwunC'></tfoot>

                1. 本文介绍了在 Django 管理更改/添加页面中显示 ForeignKey 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试让模型的属性显示在另一个模型的 Django 管理更改/添加页面中.这是我的模型:

                  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):
                      task = models.ForeignKey('Task')
                  
                  class Task(model.Model):
                      added_at = models.DateTimeField(...)
                  

                  不能切换外键,所以我不能使用内联,当然 fields = ('task__added_at',) 在这里也不起作用.

                  Can't switch the foreignkey around, so I can't use Inlines, and of course fields = ('task__added_at',) doesn't work here either.

                  这样的标准方法是什么?(还是我把 Admin 拉得太远了?)

                  What's the standard approach to something like this? (or am I stretching the Admin too far?)

                  我已经在使用自定义模板,所以如果这是可以做到的答案.但是,我更愿意在管理员级别执行此操作.

                  I'm already using a custom template, so if that's the answer that can be done. However, I'd prefer to do this at the admin level.

                  推荐答案

                  如果不需要编辑,可以显示为只读字段:

                  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
                  

                  这篇关于在 Django 管理更改/添加页面中显示 ForeignKey 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Django 管理员添加自定义过滤器 下一篇:Django Admin:按相关外键的值排序

                  相关文章

                  <legend id='cEVbq'><style id='cEVbq'><dir id='cEVbq'><q id='cEVbq'></q></dir></style></legend>

                  <i id='cEVbq'><tr id='cEVbq'><dt id='cEVbq'><q id='cEVbq'><span id='cEVbq'><b id='cEVbq'><form id='cEVbq'><ins id='cEVbq'></ins><ul id='cEVbq'></ul><sub id='cEVbq'></sub></form><legend id='cEVbq'></legend><bdo id='cEVbq'><pre id='cEVbq'><center id='cEVbq'></center></pre></bdo></b><th id='cEVbq'></th></span></q></dt></tr></i><div id='cEVbq'><tfoot id='cEVbq'></tfoot><dl id='cEVbq'><fieldset id='cEVbq'></fieldset></dl></div>

                    1. <small id='cEVbq'></small><noframes id='cEVbq'>

                      • <bdo id='cEVbq'></bdo><ul id='cEVbq'></ul>

                      <tfoot id='cEVbq'></tfoot>