Django,重写ManyToManyField
我正在基于 ManyToManyRawIdWidget 构建自己的小部件。
但是,一旦我在 ModelAdmin 中尝试以下操作:
formfield_overrides = {
ManyToManyField: {'widget': ManyToManyRawIdWidget},
}
它会提示我
__init__() takes exactly 2 arguments (1 given)
,我认为我需要用一些东西填充 rel
参数,可能是关系模型(这是一个 Tag
code> model)
但后来我遇到了 TemplateSyntaxError:
Caught AttributeError while rendering: type object 'Tag' has no attribute 'to'
这是我失去监督的地方。有人可以帮我吗?
I am sorta building my own widget, based on the ManyToManyRawIdWidget.
But as soon as i try the following in my ModelAdmin:
formfield_overrides = {
ManyToManyField: {'widget': ManyToManyRawIdWidget},
}
It'll prompt me
__init__() takes exactly 2 arguments (1 given)
I figured i needed to fill the rel
argument with something, probably the relation model (which is a Tag
model)
But then i run into a TemplateSyntaxError:
Caught AttributeError while rendering: type object 'Tag' has no attribute 'to'
This is where I lose oversight. Could someone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是想确保您注意到 formfield_overrides 的文档:
我不知道 ManyToManyRawIdWidget,但从它的名称来看,我认为在这种情况下可能会设置 raw_id_fields ?这可能就是它不起作用的原因。
Just want to make sure you heeded this warning in the documentation for formfield_overrides:
I'm not aware of the ManyToManyRawIdWidget but judging by its name I assume that raw_id_fields might be set in this case? Which might be why it isn't working.