from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import ugettext_lazy as _
class CustomUserManager(BaseUserManager):
"""
Custom user model manager where email is the unique identifiers
for authentication instead of usernames.
"""
def create_user(self, email, password, **extra_fields):
"""
Create and save a User with the given email and password.
"""
if not email:
raise ValueError(_('The Email must be set'))
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, email, password, **extra_fields):
"""
Create and save a SuperUser with the given email and password.
"""
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_active', True)
if extra_fields.get('is_staff') is not True:
raise ValueError(_('Superuser must have is_staff=True.'))
if extra_fields.get('is_superuser') is not True:
raise ValueError(_('Superuser must have is_superuser=True.'))
return self.create_user(email, password, **extra_fields)
error message:
File "C:\Users\zesha\Documents\GitHub\sust-cse-alumni-repo\users\models.py", line 6, in <module>
from .managers import CustomUserManager
File "C:\Users\zesha\Documents\GitHub\sust-cse-alumni-repo\users\managers.py", line 2, in <module>
from django.utils.translation import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (C:\Users\zesha\Documents\GitHub\sust-cse-al
umni-repo\iftu\lib\site-packages\django\utils\translation\__init__.py)
Hi NobinPegasus, ugettext_lazy` was deprecated in v2.2 and no longer used in django v3+. Check your version of django’s documentation regarding lazy translation (here’s v3.2).
the issue. Currently on each new Django 4.0.2 installation we need to:
open: /opt/homebrew/lib/python3.9/site-packages/jsonfield/fields.py
change the line 9 from:
from django.utils.translation import ugettext_lazy as _
to:
from django.utils.translation import gettext_lazy as _
What is this package “jsonfield”?
From its path, it looks like it’s a third party package and not part of Django - in which case the issue needs to be addressed by that third party library and is not a Django issue.
Where do you find the location of the folder “site-packages”?
I looked at the directory for the file
File "/home/eric/.local/lib/python3.8/site-packages/django_celery_monitor/apps.py", line 5, in <module>
from django.utils.translation import ugettext_lazy as _
and wasn’t sure where to locate the file apps.py. Would you like to provide a tutorial on where to locate the file?