gpt4 book ai didi

Django __call __()缺少1个仅关键字参数: 'manager'

转载 作者:行者123 更新时间:2023-12-03 10:38:15 24 4
gpt4 key购买 nike

我有两个模型:

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 View 来创建和查看它们。 CreateView可以正常工作并保存可以在admin中查看的信息,但是我无法获取模板来在FormView,DetailView或任何其他 View 上显示数据,因为出现此错误:
__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 查询链接的对象,并将它们保存在数据库中,所以我不知道如何继续。

最佳答案

这是我的情况,我正在使用django shell:

python manage.py shell

有两种模型: TopicEntry。我试图从 entries中获取所有 Topic,而 id1

>>> 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(),而不是 t.entry_set().all()

关于Django __call __()缺少1个仅关键字参数: 'manager' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49814669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com