Saturday, January 9, 2021

Re: UserManager creation for AbstractUserModel extended MyUser

I did paste my `models.py` with the help the help of a dpaste link.
```
class UserManagerBaseUserManager):
    
    def _create_user(selfPAN_IDpassword=None, **extra_fields):
        """
        Creates and saves a User with the given email, date of
        birth and password.
        """
        if not PAN_ID:
            raise ValueError('Users must have an email address')
        extra_fields['email'] = self.normalize_email(extra_fields["email"])
        user = self.model(PAN_ID=PAN_ID, **extra_fields)

        user.set_password(password)
        user.save(using=self._db)
        return user
    
    def create_user(selfPAN_IDpassword=None, **extra_fields):

        extra_fields.setdefault('is_staff'False)
        extra_fields.setdefault('is_superuser'False)
        return self._create_user(PAN_ID, password, **extra_fields)
    
    def create_superuser(selfPAN_IDpassword=None, **extra_fields):
        extra_fields.setdefault('is_staff'True)
        extra_fields.setdefault('is_superuser'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(PAN_ID, password, **extra_fields)


```   The following code worked. I used https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html and the source code from https://github.com/django/django/blob/master/django/contrib/auth/models.py.   Can I get help in the migrations and creating groups? Code is in the dpaste s.
On Saturday, January 9, 2021 at 7:11:23 PM UTC+5:30 Amitesh Sahay wrote:
Could you please paste your models.py


On Sat, 9 Jan 2021 at 18:36, Vishesh Mangla


(venv) PS C:\Users\Dell\OneDrive\Desktop\djangodev\mass> python manage.py createsuperuser
PAN ID: 6785
Email: s@g
Error: Enter a valid email address.
Email: s...@gmail.com
Name: fjghg
Type: fg
Error: Value 'fg' is not a valid choice.
Type: ADM
Holding: 568
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
Bypass password validation and create user anyway? [y/N]: y
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Dell\OneDrive\Desktop\djangodev\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\Dell\OneDrive\Desktop\djangodev\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Dell\OneDrive\Desktop\djangodev\venv\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Dell\OneDrive\Desktop\djangodev\venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 79, in execute
    return super().execute(*args, **options)
  File "C:\Users\Dell\OneDrive\Desktop\djangodev\venv\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Dell\OneDrive\Desktop\djangodev\venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 189, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
  File "C:\Users\Dell\OneDrive\Desktop\djangodev\mass\base\models.py", line 25, in create_superuser
    return super()._create_user(PAN_ID,  password, **extra_fields)
AttributeError: 'super' object has no attribute '_create_user'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b4ff8445-8ed7-4d29-8ae6-73f3b1f8295fn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4688ce48-bb7f-44f2-a5e2-7347579882c5n%40googlegroups.com.

No comments:

Post a Comment