当我尝试在Django Admin中删除记录时,对于某些记录,我得到
'bool'对象不可调用
我无法确定错误是基于此追溯的。
Traceback:
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
575. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
223. return view(request, *args, **kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
62. return bound_func(*args, **kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
58. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in delete_view
1736. return self._delete_view(request, object_id, extra_context)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in _delete_view
1760. [obj], opts, request.user, self.admin_site, using)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/contrib/admin/utils.py" in get_deleted_objects
131. collector.collect(objs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/contrib/admin/utils.py" in collect
195. return super().collect(objs, source_attr=source_attr, **kwargs)
File "/home/henry/Documents/Sites/Development/django-authenticjobs/env/lib/python3.6/site-packages/django/db/models/deletion.py" in collect
222. field.remote_field.on_delete(self, field, sub_objs, self.using)
Exception Type: TypeError at /admin/jobboard/job/155/delete/
Exception Value: 'bool' object is not callable
谁能建议在哪里看?谢谢
答案 0 :(得分:3)
您已将on_delete
中的ForeignKey
或OneToOneField
设置为布尔值(True
或False
)。像这样:
class SomeModel(models.Model):
some_fk = models.ForeignKey(OtherModel, on_delete=False)
您不能将此设置为布尔值。您可以将其设置为documentation中列出的值:CASCADE
,PROTECT
,SET_NULL
,SET_DEFAULT
,SET(..)
或{{1 }}。
严格来说,您也可以实施自己的策略,因为上面列出的实际上只是功能。例如CASCADE
is implemented like [GitHub]:
DO_NOTHING
尽管您可能不需要实现自己的实现,但可以选择文档中列出的一种。例如:
def CASCADE(collector, field, sub_objs, using):
collector.collect(sub_objs, source=field.remote_field.model,
source_attr=field.name, nullable=field.null)
if field.null and not connections[using].features.can_defer_constraint_checks:
collector.add_field_update(field, None, sub_objs)