title: How to fix "cannot unpack non-iterable NoneType object" error in django admin whilst using custom user model
body: <p>I am trying to use a custom user model and I am working with the <code>AbstractBaseUser</code> class. However, when I try to create a new user from the admin end, I get this error:</p>
  
  <blockquote>
    <p>"cannot unpack non-iterable NoneType object"</p>
  </blockquote>
  
  <p>I am able to view users from the admin end, but when I try to add a new user, I get this error.</p>
  
  <p>My custom user model:</p>
  
  <pre><code>class User(AbstractBaseUser):
          """docstring for Users"""
          status = (
          ('1', 'Verified'),
          ('0', 'Unverified'),
      )
  
          username = models.CharField(max_length=200,unique=True)
          email = models.EmailField(max_length=200,unique=True)
          name = models.CharField(max_length=1024)
          password = models.CharField(max_length=1024)
          phone = models.CharField(max_length=1024)
          country = models.CharField(max_length=50)
          state = models.CharField(max_length=1024)
          city = models.CharField(max_length=1024)
          address = models.CharField(max_length=1024)
          age  = models.CharField(max_length=1024, null=True)
          verified = models.CharField(max_length=1, default=0)
          verification_code = models.CharField(max_length=1024, null=True)
          is_active = models.BooleanField(default=False)
          is_admin = models.BooleanField(default=False)
          pass_code = models.CharField(max_length=1024)
          avatar = models.ImageField(upload_to=upload_user_image,default=None, max_length=1024)
          bio = models.TextField(max_length=1024,default=None)
          registration_date = models.DateTimeField()
          slug = models.SlugField(max_length=255,unique=True)
  
          objects = MyUserManager()
  
          USERNAME_FIELD = 'email'
          REQUIRED_FIELDS = ['name', 'username','phone','country','state','city','address','age','registration_date']
  
          def save(self, *args, **kwargs):
                  self.slug = slugify(self.name)
                  super(User, self).save(*args, **kwargs)
  
          def __str__(self):
                  return self.name
          def get_full_name(self):
                  return self.name
  
          def get_short_name(self):
                  return self.name
  
          def has_perm(self, perm, obj=None):
              #"Does the user have a specific permission?"
          # Simplest possible answer: Yes, always
                      return True
  
          def has_module_perms(self, app_label):
          #"Does the user have permissions to view the app `app_label`?"
          # Simplest possible answer: Yes, always
                  return True
  
          @property
          def is_staff(self):
          #"Is the user a member of staff?"
          # Simplest possible answer: All admins are staff
                  return self.is_admin
  
          def get_username(self):
           return super().get_username()
  
          def set_password(self, raw_password):
           return super().set_password(raw_password)
  
          def check_password(self, raw_password):
           return super().check_password(raw_password)
  
          def normalize_username(cls, username):
           return super().normalize_username(username)
  </code></pre>
  
  <p>My custom usermanager:</p>
  
  <pre><code>class MyUserManager(BaseUserManager):
      def create_user(self,username, name, email,phone,country,state,city,address,age,registration_date,verification_code=None,password=None):
          if not email:
              raise ValueError('Users must have an email address')
          user = self.model(
                          username = self.normalize_username(username),
                          name = name,
                          email = self.normalize_email(email),
                          phone = phone,
                          country = country,
                          state = state,
                          city = city,
                          address = address,
                          age = age,
                          verification_code = self.make_random_password(),
          )
  
          user.set_password(password)
          user.save(using=self._db)
          return user
  
      def create_superuser(self,username, name, email,phone,country,state,city,address,age,registration_date, password):
          user = self.create_user(username, name, email,phone,country,state,city,address,age,registration_date, password)
          user.is_admin = True
          user.is_active = True
          user.save(using=self._db)
          return user
  </code></pre>
  
  <p>My admin.py :</p>
  
  <pre><code>from django import forms
  from django.contrib import admin
  from django.contrib.auth.models import Group
  from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
  from django.contrib.auth.forms import ReadOnlyPasswordHashField 
  from liber.models import User
  
  
  class UserCreationForm(forms.ModelForm):
      password1 = forms.CharField(label = 'Password',widget=forms.PasswordInput)
      password2 = forms.CharField(label = 'Password Confirmation',widget=forms.PasswordInput)
  
      class Meta:
          model = User
          fields = ('name','username', 'email','phone','country','state','city','address','age','registration_date')
  
  
      def clean_password2(self):
          password1 = self.clean_data.get('password1')
          password2 = self.clean_data.get('password2')
  
          if password1 and password2 and password1 != password2:
              raise forms.ValidationError('Passwords Do Not Match')
          return password2
  
      def save(self, commit=True):
          user = super().save(commit=False)
          user.set_password(self.clean_data['password1'])
          user.verification_code = User.objects.make_random_password()
          if commit:
              user.save()
          return user
  
  class UserChangeForm(forms.ModelForm):
      password = ReadOnlyPasswordHashField()
  
      class Meta:
          model = User
          fields = ('name','username', 'email','password','phone','country','state','city','address','age','registration_date','is_active','is_admin')
  
      def clean_password(self):
          return self.initial['password']
  
  class UserAdmin(BaseUserAdmin):
      """docstring for UsersAdmin"""
      form = UserChangeForm
      add_form = UserCreationForm
      prepopulated_fields = {"slug": ("name",)}
  
      list_display = ('name','username', 'email','phone','country','state','city','address','age','registration_date','is_active','is_admin')
      list_filter = ('is_admin',)
      fieldsets = (
          (None, {'fields':('username','email','password')}),
          ('Personal info', {'fields': ('name','phone','country','state','city','address','age','registration_date',)}),
          ('Permissions', {'fields':('is_admin',)}),
      )
  
      add_fieldsets = (
          (None, {
                  'classes':('wide',),
                  'fields':('name','username', 'email','phone','country','state','city','address','age','registration_date','password1','password2')
              }
          )
      )
      search_fields = ('username','email')
      ordering = ('username','email')
      filter_horizontal = ()
  
  admin.site.register(User, UserAdmin)
  admin.site.unregister(Group)
  
  </code></pre>
  
  <p>The full traceback:</p>
  
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://127.0.0.1:8000/admin/liber/user/add/
  
  Django Version: 2.2
  Python Version: 3.7.1
  Installed Applications:
  ['liber.apps.LiberConfig',
   'dashboard.apps.DashboardConfig',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles']
  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:
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\core\handlers\exception.py" in inner
    34.             response = get_response(request)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\core\handlers\base.py" in _get_response
    115.                 response = self.process_exception_by_middleware(e, request)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\core\handlers\base.py" in _get_response
    113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\admin\options.py" in wrapper
    606.                 return self.admin_site.admin_view(view)(*args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\utils\decorators.py" in _wrapped_view
    142.                     response = view_func(request, *args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
    44.         response = view_func(request, *args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\admin\sites.py" in inner
    223.             return view(request, *args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\utils\decorators.py" in _wrapper
    45.         return bound_method(*args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\views\decorators\debug.py" in sensitive_post_parameters_wrapper
    76.             return view(request, *args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\utils\decorators.py" in _wrapper
    45.         return bound_method(*args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\utils\decorators.py" in _wrapped_view
    142.                     response = view_func(request, *args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\auth\admin.py" in add_view
    99.             return self._add_view(request, form_url, extra_context)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\auth\admin.py" in _add_view
    126.         return super().add_view(request, form_url, extra_context)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\admin\options.py" in add_view
    1634.         return self.changeform_view(request, None, form_url, extra_context)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\utils\decorators.py" in _wrapper
    45.         return bound_method(*args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\utils\decorators.py" in _wrapped_view
    142.                     response = view_func(request, *args, **kwargs)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\admin\options.py" in changeform_view
    1522.             return self._changeform_view(request, object_id, form_url, extra_context)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\admin\options.py" in _changeform_view
    1551.         ModelForm = self.get_form(request, obj, change=not add)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\auth\admin.py" in get_form
    80.         return super().get_form(request, obj, **defaults)
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\admin\options.py" in get_form
    669.             fields = flatten_fieldsets(self.get_fieldsets(request, obj))
  
  File "C:\Users\Success\Envs\libre\lib\site-packages\django\contrib\admin\utils.py" in flatten_fieldsets
    96.     for name, opts in fieldsets:
  
  Exception Type: TypeError at /admin/liber/user/add/
  Exception Value: cannot unpack non-iterable NoneType object
  </code></pre>