在 Django 管理更改/添加页面中显示外键数据
我试图让一个模型的属性显示在另一个模型的 Django 管理更改/添加页面中。这是我的模型:
class Download(model.Model):
task = models.ForeignKey('Task')
class Task(model.Model):
added_at = models.DateTimeField(...)
无法切换外键,因此我无法使用内联,当然 fields = ('task__added_at',)
在这里也不起作用。
处理此类问题的标准方法是什么? (或者我是否让管理员太过分了?)
我已经在使用自定义模板,所以如果这是可以完成的答案。但是,我更愿意在管理员级别执行此操作。
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(...)
Can't switch the foreignkey around, so I can't use Inlines, and of course fields = ('task__added_at',)
doesn't work here either.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不需要编辑它,可以将其显示为只读字段:
If you don't need to edit it, you can display it as a readonly field: