Следующая ошибка возникла во время запуска сервера при создании пользовательской модели пользователя в соответствии с руководством по Youtube: https://www.youtube.com/watch?v=HshbjK1vDtY
и застрял во время 35: 37.
Пожалуйста, помогите
Тем не менее, ошибка не выдается, если модели загружаются в admin.py через «из apps.models import User». До сих пор понятия не имею о причине.
File "/usr/lib64/python3.6/site-packages/django/contrib/admin/sites.py", line 102, in register
for model in model_or_iterable:
TypeError: 'function' object is not iterable
Ниже приведен код:
@ Models.py
#models.py
class UserManager(BaseUserManager):
def create_user(self, email, password=None, is_active=True, is_staff=False, is_admin=False):
if not email:
raise ValueError("Users must have an email address")
if not password:
raise ValueError("User must have a password")
user_obj = self.model(
email = self.normalize_email(email)
)
user_obj.set_password(password) #change user password
user_obj.staff = is_staff
user_obj.admin = is_admin
user_obj.active = is_active
user_obj.save(using=self._db)
return user_obj
def create_staffuser(self, email, password=None):
user = self.create_user(
email,
password = password,
is_staff = True
)
user.save(using=self._db)
return user
def create_superuser(self, email, password=None):
user = self.create_user(
email,
password = password,
is_staff = True,
is_admin = True
)
user.save(using=self._db)
return user
class User(AbstractBaseUser):
"""User model."""
email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
full_name = models.CharField(max_length=255, blank=True, null=True)
active = models.BooleanField(default=True) #can login
staff = models.BooleanField(default=False) #staff user non superuser
admin = models.BooleanField(default=False) #superuser
#confirm = models.BooleanField(default=False) #
timestamp = models.DateTimeField(auto_now_add = True)
user_type = models.CharField(max_length=10, null=True)
username = None
def __iter__(self):
return [
'''
self.email,
self.full_name,
self.active,
self.staff,
self.admin,
self.timestamp,
self.user_type,
'''
]
USERNAME_FIELD = 'email'
#Username_Field and password are required by default
REQUIRED_FIELDS = [] #['full_name'] #python manage.py createsuperuser.
object = UserManager()
def get_full_name(self):# The user is identified by their email address
return self.full_name
def get_short_name(self): # The user is identified by their email address
return self.full_name
def __str__(self):# __unicode__ on Python 2
return self.email
def has_perm(self, perm, obj=None):# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):# Simplest possible answer: Yes, always
return True
class Meta:
ordering = ['email']
@property
def is_staff(self): #Is the user a member of staff?
return self.staff
@property
def is_admin(self):
return self.admin
@property
def is_active(self):
return self.active
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
#extend extra data
@setting.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis.db',
'django.core.handlers.wsgi',
'app',
'django.contrib.gis',
'mail.apps.MailConfig',
'multiselectfield',
'import_export',
]
AUTH_USER_MODEL = 'app.User'
@admin.py
from django.contrib import admin
from django.contrib.auth import get_user_model
from import_export import resources
from import_export.admin import ImportExportModelAdmin
from django.contrib.gis.admin import OSMGeoAdmin
User = get_user_model
#from .forms import CustomUserCreationForm, CustomUserChangeForm
from app.models import ..., User
admin.site.register(User)