相关疑难解决方法(0)

Django InlineModelAdmin:部分显示内联模型并链接到完整模型

我定义了几个模型:期刊,卷,volume_scanInfo等.

日志可以拥有更多卷,而卷可以拥有更多scanInfo.

我想做的是:

  • 在期刊的管理页面中我想要内联的卷列表(完成)
  • 将上一个列表的每个卷连接到其管理页面,我可以在其中显示表单以编辑卷以及内联的"扫描信息"列表.

所以我希望有类似的东西:

Journal #1 admin page
[name]
[publisher]
[url]
.....
list of volumes inline
    [volume 10] [..(other fields)..]   <a href="/link/to/volume/10">Full record</a>
    [volume 20] [..(other fields)..]   <a href="/link/to/volume/20">Full record</a>
Run Code Online (Sandbox Code Playgroud)

然后

Volume #20 admin page
[volume number]
[..(other fields)...]
......
list of the scan info inline
    [scan info 33] [..(other fields)..]   <a href="/link/to/scaninfo/33">Full record</a>
    [scan info 44] [..(other fields)..]   <a href="/link/to/scaninfo/44">Full record</a>
Run Code Online (Sandbox Code Playgroud)

我尝试做的是定义一个模型方法,该方法创建代码并尝试在管理中定义"volume inline"的类中使用它,但它不起作用.

换一种说法

模型"卷"有类似于:

def selflink(self):
    return '<a href="/admin/journaldb/volume/%s/">Full record</a>' % self.vid
selflink.allow_tags = True
Run Code Online (Sandbox Code Playgroud)

和 …

python django django-admin

32
推荐指数
4
解决办法
2万
查看次数

标签 统计

django ×1

django-admin ×1

python ×1