当我尝试从管理面板中删除用户时出现此类错误
在/ admin / auth / user /中的TypeError “布尔”对象不可调用
models.py
class PROFILE(models.Model):
kullanıcı = models.OneToOneField(User,on_delete=True)
birthday = models.DateField(verbose_name="Birthday",
blank=False,null=False)
gender = models.CharField(max_length=15, blank=False,null=
False,choices=gender)
language = models.CharField(max_length=20, blank=False,null=False,
verbose_name="language",choices=languages)
def set_token(self):
self.token = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789')
for i in range(15)])
def save(self, *args, **kwargs):
super(PROFILE, self).save(*args, **kwargs)
self.set_token()
class Meta:
verbose_name_plural = 'PROFILE'
ordering= ["id"]
def __str__(self):
return "{}".format(self.kullanıcı.username)
class Q(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
... class Meta, __str__ ....
首先,“kullanıcı”是“用户”,但由于django冲突的可能性,我进行了更改。但是我仍然有这个问题
在/ admin / auth / user /中的TypeError '布尔'对象不可调用 请求方法:POST 要求网址:http://192.168.1.34:8000/admin/auth/user/ Django版本:2.1 异常类型:TypeError 异常值:
'布尔'对象不可调用 异常位置:在收集行第221行中的/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/db/models/deletion.py Python可执行文件:/ home / mete /Masaüstü/ ask / venv / bin / python Python版本:3.6.5 Python路径:
['/ home / mete /Masaüstü/ ask / ask', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages'] 服务器时间:Cum,31Ağu2018 16:35:51 +0000
>
跟踪: 内部文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/core/handlers/exception.py” 34. response = get_response(请求) _get_response中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/core/handlers/base.py” 126. response = self.process_exception_by_middleware(e,request) _get_response中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/core/handlers/base.py” 124. response = wrapd_callback(request,* callback_args,** callback_kwargs) 包装文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py” 607. return self.admin_site.admin_view(view)(* args,** kwargs) _wrapped_view中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py” 142. response = view_func(request,* args,** kwargs) _wrapped_view_func中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/views/decorators/cache.py” 44. response = view_func(request,* args,** kwargs) 内部文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/sites.py” 223. return view(request,* args,** kwargs) _wrapper中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py” 45. return bound_method(* args,** kwargs) _wrapped_view中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py” 142. response = view_func(request,* args,** kwargs) 在changelist_view中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py” 1711. response = self.response_action(request,queryset = cl.get_queryset(request)) 在response_action中文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py” 1411. response = func(self,request,queryset) 在delete_selected中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/actions.py” 28. deletable_objects,model_count,perms_needed,protected = modeladmin.get_deleted_objects(queryset,request)> 在get_deleted_objects中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py” 1833.返回get_deleted_objects(objs,request,self.admin_site) 在get_deleted_objects中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/utils.py” 134. collector.collect(objs) 收集中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/utils.py” 197. return super()。collect(objs,source_attr = source_attr,** kwargs) 收集中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/db/models/deletion.py” 221. field.remote_field.on_delete(self,field,sub_objs,self.using)
异常类型:/ admin / auth / user /中的TypeError 异常值:“布尔”对象不可调用
答案 0 :(得分:2)
问题出在您的 on_delete
模型的 Profile
参数中。
on_delete
自变量不应是 boolean 的值。 on_delete
的可能值可在此处Related Field- on_delete
中找到。
因此,将您的 PROFILE
更改为
class PROFILE(models.Model):
kullanıcı = models.OneToOneField(User,on_delete=models.CASCADE)
.... other fields