我有两种模式:
class Someinfo(models.Model):
name = models.CharField(max_length=200)
#something else
class OtherInfo(models.Model):
name2 = models.CharField(max_lenth=200)
related_someinfo = models.ManyToManyField(Someinfo)
#something else
现在我创建了CBV视图来创建和查看它们。 CreateView工作正常,并保存可以在管理员中查看的信息,但我无法让模板在任何其他视图上显示数据,无论是FormView,DetailView还是其他任何视图,因为我收到此错误:
__call__() missing 1 required keyword-only argument: 'manager'
Request Method: GET
Request URL: http://something
Django Version: 2.0.3
Exception Type: TypeError
Exception Value:
__call__() missing 1 required keyword-only argument: 'manager'
Exception Location: /usr/local/lib/python3.5/dist-packages/django/forms/forms.py in get_initial_for_field, line 494
Python Executable: /usr/bin/python3
Python Version: 3.5.3
检查forms.py中的行,它显示不起作用的函数是:
def get_initial_for_field(self, field, field_name):
"""
Return initial data for field on form. Use initial data from the form
or the field, in that order. Evaluate callable values.
"""
value = self.initial.get(field_name, field.initial)
if callable(value):
value = value() # line 494
return value
有什么建议吗?我可以通过shell查询链接对象,它们保存在数据库中,所以我不知道如何继续。
答案 0 :(得分:2)
这是我的情况,我使用的是django shell:
python manage.py shell
有两种模型:Topic
和Entry
。我试图从entries
是Topic
的{{1}}获取所有id
。
1
正确的命令是:>>> Topic.objects.get(id=1)
<Topic: Chess>
>>> t = Topic.objects.get(id=1)
>>> t.entry_set().all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: __call__() missing 1 required keyword-only argument: 'manager'
>>> t.entry_set.all()
<QuerySet [<Entry: Ah okey, so when testing for a console.log (or oth...>]>
>>>
,而不是t.entry_set.all()
答案 1 :(得分:1)
使用entry_set而不是entry_set()(没有括号)