Django Admin内联递归ManyToMany
我有以下模型,其本身具有多对多关系,
class Ticket(models.Model):
STATUS = (
(0, "Open"),
(1, "Closed"),
)
status = models.SmallIntegerField(default=0,choices=STATUS)
title = models.CharField(max_length=100)
replies = models.ManyToManyField('self')
description = models.TextField()
我试图使用以下代码将此模型显示为管理中的内联模型,
class TicketReply(admin.TabularInline):
model = Ticket.replies.through
但是我不断收到此错误
<class 'tsn.ticket.models.Ticket_replies'> has more than 1 ForeignKey to <class 'tsn.ticket.models.Ticket'>
,所以我做错了,或者这不是支持?
I have the following model with a many-to-many relationship to itself
class Ticket(models.Model):
STATUS = (
(0, "Open"),
(1, "Closed"),
)
status = models.SmallIntegerField(default=0,choices=STATUS)
title = models.CharField(max_length=100)
replies = models.ManyToManyField('self')
description = models.TextField()
i am trying to display this model as an inline in the admin, using the following code
class TicketReply(admin.TabularInline):
model = Ticket.replies.through
however i keep getting this error
<class 'tsn.ticket.models.Ticket_replies'> has more than 1 ForeignKey to <class 'tsn.ticket.models.Ticket'>
so im i doing this wrong, or is this not supported ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能已经太晚了,但我尝试回答这个问题。 Ticket.replies.through 是一个管理多对多关系的表,它有字段 from_ticket 和 to_ticket(FK to model Ticket),您可以将此字段设置为 TabularInline 的选项 fk_name 。
May be its' to late, but I try answer this question. Ticket.replies.through is a table to manage many-to-many relations, it has fields from_ticket and to_ticket(FK to model Ticket) and you can set this fields as option fk_name for TabularInline.