私は正常に動作していた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