/ admin / auth / user /中的TypeError

loading...


2

当我尝试从管理面板中删除用户时出现这样的错误

/ admin / auth / user /'bool'对象中的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 /'bool'对象中的TypeError不可调用请求方法:POST请求URL:http://192.168.1.34:8000 / admin / auth / user / Django版本:2.1异常类型:TypeError异常值:'bool'对象不可调用异常位置:/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/db/models/deletion.pyin collect,第221行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 /mallástü/ tar / venv / lib / python3.6 / site-package']服务器时间:暨,31Ağu2018816:35:51 0000

回溯:文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/core/handlers/exception.py”在内部34. response = get_response(request)File“/ home /mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/core/handlers/base.py“in _get_response 126. response = self.process_exception_by_middleware(e,request)File”/ home / mete / Masaüstü/ ask / venv / lib / python3.6 / site-packages / django / core / handlers / base.py“in _get_response 124. response = wrapped_callback(request,* callback_args,** callback_kwargs)File”/ home / mete / Masaüstü/ ask / venv / lib / python3.6 / site-packages / django / contrib / admin / options.py“在包装器607中 . 返回self.admin_site.admin_view(查看)(* args,** kwargs)文件”/ home / mete /Masaüstü/ ask / venv / lib / python3.6 / site-packages / django / utils / decorators.py“in _wrapped_view 142. response = view_func(request,* args,** kwargs)File”/ home / mete /Masaüstü/ ask / venv / lib / python3.6 / site-packages / django / views / decorators / cache.py“in _wrapped_view_func 44. response = view_f unc(request,* args,** kwargs)文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/sites.py”在内部223.返回视图(请求,* args,** kwargs)文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py”在_wrapper 45.中返回bound_method(* args) ,** kwargs)在_wrapped_view 142中输入文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/utils/decorators.py”.response = view_func(request,* args,* * kwargs)在changelist_view 1711中输入文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py”.response = self.response_action(request,queryset = cl.get_queryset(request))在response_action 1411中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py”.response = func(self,请求,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 1833中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/options.py”返回get_deleted_objects(objs,request,self.admin_site)get_deleted_objects 134中的文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/utils.py” . 收集器.collect(objs)文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/contrib/admin/utils.py”在collect 197. return super() . collect(objs) ,source_attr = source_attr,** kwargs)在collect 221. field.remote_field中输入文件“/home/mete/Masaüstü/ask/venv/lib/python3.6/site-packages/django/db/models/deletion.py” . on_delete(self,field,sub_objs,self.using)异常类型:/ admin / auth / user / Exception中的TypeError:'bool'对象不可调用

1回答

  • 1

    问题出在 Profile 模型的 on_delete 参数中 .

    on_delete 参数 should notboolean 值 . on_delete 的可能值可在此处找到,Related Field- on_delete .

    所以,改变你的 PROFILE

    class PROFILE(models.Model):
        kullanıcı = models.OneToOneField(User,on_delete=models.CASCADE)
        .... other fields
    

loading...

评论

暂时没有评论!