<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 数据

        Displaying ForeignKey data in Django admin change/add page(在 Django 管理更改/添加页面中显示 ForeignKey 数据)

            <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 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                    <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>

                        <tbody id='cEVbq'></tbody>

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

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

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