File “C:\Users\Emmanuel_coder\Desktop\JMS\userauths\models.py”, line 78, in create_user_profile
Profile.objects.create(user=instance)
^^^^^^^^^^^^^^^
AttributeError: type object ‘Profile’ has no attribute ‘objects’
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
If you are requesting assistance, please do 2 things.
1 - You need to post your models.py file as I’ve been asking.
2 - When you post code here, you need to post the code correctly, as described above.
from cProfile import Profile
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db.models.signals import post_save
from shortuuid.django_fields import ShortUUIDField
GENDER = (
(“Female”, “Female”),
(“Male”, “Male”),
(“Other”, “Other”),
)
IDENTITY_TYPE = (
(“National Identification Number”,“National Identification Number”),
(“Driver’s License”, “Driver’s License”),
(“Internationa Passport”, “Internationa Passport”),
)
def user_directory_path(instance, filename):
ext = filename.split(“.”)[-1]
filename = “%s.%s” % (instance.user.id, filename)
return “user_(0)/(1)”.format(instance.user.id, filename)
class User(AbstractUser):
full_name = models.CharField(max_length=500, null=True, blank=True)
username = models.CharField(max_length=500, unique=True)
email = models.EmailField(unique=True)
phone = models.CharField(max_length=100, null=True, blank=True)
gender = models.CharField(max_length=20, choices=GENDER, default=“other”)
otp = models.CharField(max_length=100, null=True, blank=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
def __str__(self):
return self.username
#Himselv User
class Profile(models.Model):
pid = ShortUUIDField(length=7, max_length=25, alphabet="abcdefghijklmnopqrstuvwxyz123")
image = models.FileField(upload_to=user_directory_path, default="default.jpg", null=True, blank=True)
user = models.OneToOneField("User", on_delete=models.CASCADE)
full_name = models.CharField(max_length=500, null=True, blank=True)
phone = models.CharField(max_length=100, null=True, blank=True)
gender = models.CharField(max_length=20, choices=GENDER, default="other")
country = models.CharField(max_length=100, null=True, blank=True)
city = models.CharField(max_length=100, null=True, blank=True)
state = models.CharField(max_length=100, null=True, blank=True)
address = models.CharField(max_length=1000, null=True, blank=True)
identity_type = models.CharField(max_length=200, choices=IDENTITY_TYPE, null=True, blank=True)
identity_image = models.FileField(upload_to=user_directory_path, default="default.jpg", null=True, blank=True)
facebook = models.URLField(null=True, blank=True)
twitter = models.URLField(null=True, blank=True)
wallet = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)
verified = models.BooleanField(default=False)
date = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ["-date"]
def __str__(self):
if self.full_name:
return f"{self.full_name}"
else:
return f"{self.user.username}"
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
post_save.connect(create_user_profile, sender=User)
post_save.connect(save_user_profile, sender=User)
PS C:\Users\Emmanuel_coder\Desktop\JMS> py manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\threading.py”, line 1075, in _bootstrap_inner
self.run()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\threading.py”, line 1012, in run
self.target(*self.args, **self.kwargs)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\commands\runserver.py”, line 126, in inner_run
autoreload.raise_last_exception()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 87, in raise_last_exception
raise exception[1]
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management_init.py", line 394, in execute
autoreload.check_errors(django.setup)()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django_init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\apps\registry.py”, line 124, in populate
app_config.ready()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\apps.py”, line 27, in ready
self.module.autodiscover()
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin_init.py", line 52, in autodiscover
autodiscover_modules(“admin”, register_to=site)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\module_loading.py”, line 58, in autodiscover_modules
import_module(“%s.%s” % (app_config.name, module_to_search))
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\importlib_init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 1387, in _gcd_import
File “”, line 1360, in _find_and_load
File “”, line 1331, in _find_and_load_unlocked
File “”, line 935, in _load_unlocked
File “”, line 995, in exec_module
File “”, line 488, in _call_with_frames_removed
File “C:\Users\Emmanuel_coder\Desktop\JMS\userauths\admin.py”, line 14, in
admin.site.register(Profile, ProfileAdmin)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\sites.py”, line 110, in register
for model in model_or_iterable:
^^^^^^^^^^^^^^^^^
TypeError: ‘type’ object is not iterable
This line should not be anywhere in your code. You have it in both your models.py and your admin.py files. Delete them.
i have but still not working
PS C:\Users\Emmanuel_coder\Desktop\JMS> py manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\threading.py”, line 1075, in _bootstrap_inner
self.run()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\threading.py”, line 1012, in run
self.target(*self.args, **self.kwargs)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\commands\runserver.py”, line 126, in inner_run
autoreload.raise_last_exception()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 87, in raise_last_exception
raise exception[1]
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management_init.py", line 394, in execute
autoreload.check_errors(django.setup)()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django_init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\apps\registry.py”, line 124, in populate
app_config.ready()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\apps.py”, line 27, in ready
self.module.autodiscover()
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin_init.py", line 52, in autodiscover
autodiscover_modules(“admin”, register_to=site)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\module_loading.py”, line 58, in autodiscover_modules
import_module(“%s.%s” % (app_config.name, module_to_search))
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\importlib_init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 1387, in _gcd_import
File “”, line 1360, in _find_and_load
File “”, line 1331, in _find_and_load_unlocked
File “”, line 935, in _load_unlocked
File “”, line 995, in exec_module
File “”, line 488, in _call_with_frames_removed
File “C:\Users\Emmanuel_coder\Desktop\JMS\userauths\admin.py”, line 2, in
from userauths.models import User,Profile
ImportError: cannot import name ‘Profile’ from ‘userauths.models’ (C:\Users\Emmanuel_coder\Desktop\JMS\userauths\models.py)
Profile.objects.create(user = instance)
line showing under the profile
‘’'from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db.models.signals import post_save
from shortuuid.django_fields import ShortUUIDField
GENDER = (
(“Female”, “Female”),
(“Male”, “Male”),
(“Other”, “Other”),
)
IDENTITY_TYPE = (
(“National Identification Number”,“National Identification Number”),
(“Driver’s License”, “Driver’s License”),
(“Internationa Passport”, “Internationa Passport”),
)
def user_directory_path(instance, filename):
ext = filename.split(“.”)[-1]
filename = “%s.%s” % (instance.user.id, filename)
return “user_(0)/(1)”.format(instance.user.id, filename)
class User(AbstractUser):
full_name = models.CharField(max_length=500, null=True, blank=True)
username = models.CharField(max_length=500, unique=True)
email = models.EmailField(unique=True)
phone = models.CharField(max_length=100, null=True, blank=True)
gender = models.CharField(max_length=20, choices=GENDER, default=“other”)
otp = models.CharField(max_length=100, null=True, blank=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
def __str__(self):
return self.username
#Himselv User
class Profile(models.Model):
pid = ShortUUIDField(length=7, max_length=25, alphabet="abcdefghijklmnopqrstuvwxyz123")
image = models.FileField(upload_to=user_directory_path, default="default.jpg", null=True, blank=True)
user = models.OneToOneField("user", on_delete=models.CASCADE)
full_name = models.CharField(max_length=500, null=True, blank=True)
phone = models.CharField(max_length=100, null=True, blank=True)
gender = models.CharField(max_length=20, choices=GENDER, default="other")
country = models.CharField(max_length=100, null=True, blank=True)
city = models.CharField(max_length=100, null=True, blank=True)
state = models.CharField(max_length=100, null=True, blank=True)
address = models.CharField(max_length=1000, null=True, blank=True)
identity_type = models.CharField(max_length=200, choices=IDENTITY_TYPE, null=True, blank=True)
identity_image = models.FileField(upload_to=user_directory_path, default="default.jpg", null=True, blank=True)
facebook = models.URLField(null=True, blank=True)
twitter = models.URLField(null=True, blank=True)
wallet = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)
verified = models.BooleanField(default=False)
date = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ["-date"]
def __str__(self):
if self.full_name:
return f"{self.full_name}"
else:
return f"{self.user.username}"
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user = instance)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
post_save.connect(create_user_profile, sender=User)
post_save.connect(save_user_profile, sender=User) ‘’’
‘’'from django.contrib import admin
from userauths.models import User,Profile
class UserAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘username’]
list_display = [‘username’, ‘full_name’, ‘email’, ‘phone’, ‘gender’]
class ProfileAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘user_username’]
list_display = [‘username’, ‘user’, ‘verified’]
admin.site.register(User, UserAdmin)
admin.site.register(Profile, ProfileAdmin)‘’’
models.py
from django.contrib.auth.models import AbstractUser
from django.db.models.signals import post_save
from shortuuid.django_fields import ShortUUIDField
GENDER = (
("Female", "Female"),
("Male", "Male"),
("Other", "Other"),
)
IDENTITY_TYPE = (
("National Identification Number","National Identification Number"),
("Driver's License", "Driver's License"),
("Internationa Passport", "Internationa Passport"),
)
def user_directory_path(instance, filename):
ext = filename.split(".")[-1]
filename = "%s.%s" % (instance.user.id, filename)
return "user_(0)/(1)".format(instance.user.id, filename)
class User(AbstractUser):
full_name = models.CharField(max_length=500, null=True, blank=True)
username = models.CharField(max_length=500, unique=True)
email = models.EmailField(unique=True)
phone = models.CharField(max_length=100, null=True, blank=True)
gender = models.CharField(max_length=20, choices=GENDER, default="other")
otp = models.CharField(max_length=100, null=True, blank=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
def __str__(self):
return self.username
#Himselv User
class Profile(models.Model):
pid = ShortUUIDField(length=7, max_length=25, alphabet="abcdefghijklmnopqrstuvwxyz123")
image = models.FileField(upload_to=user_directory_path, default="default.jpg", null=True, blank=True)
user = models.OneToOneField("User", on_delete=models.CASCADE)
full_name = models.CharField(max_length=500, null=True, blank=True)
phone = models.CharField(max_length=100, null=True, blank=True)
gender = models.CharField(max_length=20, choices=GENDER, default="other")
country = models.CharField(max_length=100, null=True, blank=True)
city = models.CharField(max_length=100, null=True, blank=True)
state = models.CharField(max_length=100, null=True, blank=True)
address = models.CharField(max_length=1000, null=True, blank=True)
identity_type = models.CharField(max_length=200, choices=IDENTITY_TYPE, null=True, blank=True)
identity_image = models.FileField(upload_to=user_directory_path, default="default.jpg", null=True, blank=True)
facebook = models.URLField(null=True, blank=True)
twitter = models.URLField(null=True, blank=True)
wallet = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)
verified = models.BooleanField(default=False)
date = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ["-date"]
def __str__(self):
if self.full_name:
return f"{self.full_name}"
else:
return f"{self.user.username}"
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user = instance)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
post_save.connect(create_user_profile, sender=User)
post_save.connect(save_user_profile, sender=User)```
admin.py
from userauths.models import User,Profile
class UserAdmin(admin.ModelAdmin):
search_fields = ['full_name', 'username']
list_display = ['username', 'full_name', 'email', 'phone', 'gender']
class ProfileAdmin(admin.ModelAdmin):
search_fields = ['full_name', 'user_username']
list_display = ['username', 'user', 'verified']
admin.site.register(User, UserAdmin)
admin.site.register(Profile, ProfileAdmin)```
One major issue here is that your Profile
model is indented within the User
model.
Your Profile
class needs to be shifted left so that it is indented the same as your User
model.
(You’ll need to run makemigrations
and migrate
after fixing this.)
okay let check if it works
SystemCheckError: System check identified some issues:
ERRORS:
<class 'hotel.admin.ProfileAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'username', which is not a callable or attribute of 'ProfileAdmin', or an attribute, method, or field on 'userauths.Profile'.```
SystemCheckError: System check identified some issues:
ERRORS:
<class 'hotel.admin.ProfileAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'username', which is not a callable or attribute of 'ProfileAdmin', or an attribute, method, or field on 'userauths.Profile'.```
What information do you think that this error message is giving you?
I have no idea daddy
So let’s split this apart.
Looking at the error, what Class is it finding the error in?