我有两个模型:
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
Run Code Online (Sandbox Code Playgroud)
现在我已经创建了 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
Run Code Online (Sandbox Code Playgroud)
检查 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
Run Code Online (Sandbox Code Playgroud)
有什么建议?我可以通过 shell 查询链接的对象并将它们保存在数据库中,所以我不知道如何继续。
sli*_*wp2 18
这是我的情况,我使用的是 django shell:
python manage.py shell
Run Code Online (Sandbox Code Playgroud)
有两种型号:Topic和Entry。我试图让所有entries的Topic这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...>]>
>>>
Run Code Online (Sandbox Code Playgroud)
正确的命令是:t.entry_set.all(), nott.entry_set().all()
| 归档时间: |
|
| 查看次数: |
8507 次 |
| 最近记录: |