我有一个运行良好的 django 项目。我得到了包括电话验证的要求,所以我使用了 twilio 并使用了 django [电话号码] [1]。我做了验证部分,一切正常,直到我尝试从管理面板中删除用户时注意到以下异常。
我不是 100% 确定它是否与电话号码有关,因为这是添加到项目中的唯一新事物。我尝试从管理面板添加和更新新用户,效果很好。问题在于删除用户。
Request URL: http://127.0.0.1:8000/admin/projectapp/customuser/
Django Version: 3.0.8
Python Version: 3.8.4
Installed Applications:
['django.contrib.admin',
'django.contrib.gis',
'projectapp',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'phonenumber_field',
'verify_email.apps.VerifyEmailConfig',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\options.py", line 1704, in changelist_view
response = self.response_action(request, queryset=cl.get_queryset(request))
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\options.py", line 1390, in response_action
response = func(self, request, queryset)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\actions.py", line 28, in delete_selected
deletable_objects, model_count, perms_needed, protected = modeladmin.get_deleted_objects(queryset, request)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\options.py", line 1826, in get_deleted_objects
return get_deleted_objects(objs, request, self.admin_site)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\utils.py", line 151, in get_deleted_objects
to_delete = collector.nested(format_callback)
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\utils.py", line 211, in nested
roots.extend(self._nested(root, seen, format_callback))
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\utils.py", line 195, in _nested
children.extend(self._nested(child, seen, format_callback))
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\utils.py", line 197, in _nested
ret = [format_callback(obj)]
File "D:\installedSoft\Python\Python38-32\lib\site-packages\django\contrib\admin\utils.py", line 126, in format_callback
no_edit_link = '%s: %s' % (capfirst(opts.verbose_name), obj)
Exception Type: TypeError at /admin/projectapp/customuser/
Exception Value: __str__ returned non-string (type NoneType)
这是我的用户模型类
class CustomUser(AbstractUser):
username = None
email = models.EmailField(_('email address'), unique=True)
zipcode = models.CharField(max_length=10, blank=True,verbose_name='zip code')
full_name = models.CharField(max_length=100, blank=True,verbose_name='Full name')
gender = models.CharField(max_length=8, blank=True,verbose_name='gender')
donation_amount = models.FloatField(max_length=10, blank=False,default=0, verbose_name='donation amount' )
phone_number = PhoneNumberField(null=False, blank=False, unique=True) #models.BigIntegerField(blank=True)
country_code = models.IntegerField(default=1)
two_factor_auth = models.BooleanField(default=False)
is_verified = models.BooleanField(default=False)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['full_name', 'phone_number', 'country_code']
objects = CustomUserManager()
def __str__(self):
return self.email