Did you happen to remove the private method "def _create_user" from your 
models.py?


Regards,
Amitesh  

    On Saturday, 9 January, 2021, 08:08:16 pm IST, Vishesh Mangla 
<manglavishes...@gmail.com> wrote:  
 
 Oops I guess, my bad messaging style made you miss the last few pieces of my 
messages. Thanks, but that problem is resolved as written in my previous 
message with the working code. Now I require help with the Migrations problem.

On Saturday, January 9, 2021 at 8:00:55 PM UTC+5:30 Amitesh Sahay wrote:

Hello Vishesh, 
Below is from my models.py:
models.py-------------from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.utils.translation import gettext_lazy as _


class AccountManager(BaseUserManager):
    def create_superuser(self, email, password, **extra_fields):
        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)

    def create_user(self, email, password, **extra_fields):
        if not email:
            raise ValueError(_('Enter the email before proceeding'))

        email = self.normalize_email(email)
        user = self.model(email=email, password=password, **extra_fields)
        user.set_password(password)
        user.save()
        return user


class Shop(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True)
    shop_name = models.CharField(max_length=150)
    contact = models.CharField(max_length=10)
    State = models.CharField(max_length=100)
    district = models.CharField(max_length=100)
    location = models.CharField(max_length=100)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(auto_now_add=True)
    last_login = models.DateTimeField(null=True)

    objects = AccountManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['shop_name', 'contact', 'is_staff']

    def __str__(self):
        return str(self.shop_name)
See if that helps you out.


Regards,
Amitesh 

    On Saturday, 9 January, 2021, 07:39:18 pm IST, Vishesh Mangla 
<manglav...@gmail.com> wrote:  
 
 I did paste my `models.py` with the help the help of a dpaste link. 
```class UserManager( BaseUserManager):        def _create_user(self, PAN_ID, 
password=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(self, PAN_ID, password=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(self, PAN_ID, password=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

Sent from Yahoo Mail on Android 
 


  On Sat, 9 Jan 2021 at 18:36, Vishesh Mangla<manglav...@gmail.com> wrote:  

https://dpaste.org/Zz5Z

(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...@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.
  


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/542f9408-64f4-4b68-a7a0-f4b9e9402538n%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1431603937.136044.1610203901335%40mail.yahoo.com.

Reply via email to