For creating Custom Users I have found util the tutorial: Creating a Custom 
User Model in Django of  Michael Herman 
https://testdriven.io/blog/django-custom-user-model/  

Best wishes.

Ángeles.
El domingo, 4 de abril de 2021 a la(s) 05:03:37 UTC-5, [email protected] 
escribió:

> Hi Amitesh,
>
> unfortunately, nothing changed... I mean it is just weird that I am having 
> now those different tables in auth and users app (see picture).
> I can add and manage groups for auth_group but I would love to manage 
> those via users_account_groups.... any ideas?
>
> Also currently my groups are stored in auth_group while the permission and 
> user allocation is stored in users_account_groups as well as 
> users_account_user_permissions...
> Is this normal?
>
> [image: Screenshot 2021-04-04 at 10.26.11.png]
>
> Best wishes,
>
> Manuel
>
>
>
> Manuel Buri
> T:  +41 79 933 01 11 <+41%2079%20933%2001%2011> 
> M: [email protected]
> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>
>
> On Sun, 4 Apr 2021 at 07:00, 'Amitesh Sahay' via Django users <
> [email protected]> wrote:
>
>> Hello Manuel, 
>>
>> Try the below. Recently I have worked on custom user model:
>>
>> 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):
>>         extra_fields.setdefault('is_staff', False)
>>         extra_fields.setdefault('is_superuser', False)
>>         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
>>
>> see if these changes make any difference.
>>
>> Regards,
>> Amitesh 
>>
>>
>> On Saturday, 3 April, 2021, 10:24:52 pm IST, Manuel Buri <
>> [email protected]> wrote: 
>>
>>
>> Hi, 
>>
>> I have a custom user model (see below) with inheritance from 
>> AbstractBaseUser and PermissionMixin. Therefore I have not only the 
>> auth_group, auth_group_permissions and auth_permissions tables but also 
>> those for my custom user model called 'Account'.
>>
>> Currently I have the following problem: I cannot add groups to the custom 
>> user model group but I can add to auth_group. Also in django admin looking 
>> at the custom user table I can see the auth_group... which is weird... I 
>> think I have done an error or missed something while setting it up... thank 
>> you very much for your help.
>>
>> from django.db import models
>> from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, 
>> PermissionsMixin
>> from django.contrib.auth.models import User
>> from organization.models import Organization
>>
>> class MyAccountManager(BaseUserManager):
>>
>> def create_user(self, email, first_name, last_name, password=None):
>> if not email:
>> raise ValueError('Users must have an email address')
>> if not first_name:
>> raise ValueError('Users must have a first name')
>> if not last_name:
>> raise ValueError('Users must have a last name')
>>
>> user = self.model(
>> email=self.normalize_email(email),
>> first_name=first_name,
>> last_name=last_name
>> )
>> user.set_password(password)
>> user.save(using=self._db)
>> return user
>>
>> def create_superuser(self, email, first_name, last_name ,password):
>> user = self.create_user(
>> email=self.normalize_email(email),
>> password=password,
>> first_name=first_name,
>> last_name=last_name
>> )
>> user.is_admin = True
>> user.is_staff = True
>> user.is_superuser = True
>> user.save(using=self._db)
>> return user
>>
>>
>> class Account(AbstractBaseUser, PermissionsMixin):
>> email = models.EmailField(verbose_name="email", max_length=60, 
>> unique=True)
>> # username = models.CharField(max_length=30, unique=True)
>> # TODO: for production do not allow null field
>> first_name = models.CharField(verbose_name="first_name", max_length=40)
>> last_name = models.CharField(verbose_name="last_name", max_length=40)
>> full_name = models.CharField(verbose_name="full_name", max_length=80)
>> # 1 Employee has 1 Organization, but 1 Organization has many employees
>> organization = models.ForeignKey(Organization, on_delete=models.CASCADE, 
>> null=True)
>> date_joined = models.DateTimeField(verbose_name='date joined', 
>> auto_now_add=True)
>> last_login = models.DateTimeField(verbose_name='last login', 
>> auto_now=True)
>> is_admin = models.BooleanField(default=False)
>> is_active = models.BooleanField(default=True)
>> is_staff = models.BooleanField(default=False)
>> is_superuser = models.BooleanField(default=False)
>>
>>
>> USERNAME_FIELD = "email"
>> REQUIRED_FIELDS = ["first_name", "last_name",]
>>
>> objects = MyAccountManager()
>>
>> def __str__(self):
>> return self.email
>>
>> # For checking permissions. to keep it simple all admin have ALL 
>> permissions
>> def has_perm(self, perm, obj=None):
>> return self.is_admin
>>
>> # Does this user have permission to view this app? (ALWAYS YES FOR 
>> SIMPLICITY)
>> def has_module_perms(self, app_label):
>> return True
>>
>>
>> -- 
>> 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 [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/38882988-f54d-4830-9cbd-9b9ad49349c0n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/38882988-f54d-4830-9cbd-9b9ad49349c0n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> -- 
>>
> You received this message because you are subscribed to a topic in the 
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/django-users/kWu37UERkvw/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/1261334457.2585167.1617512381261%40mail.yahoo.com
>>  
>> <https://groups.google.com/d/msgid/django-users/1261334457.2585167.1617512381261%40mail.yahoo.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/507772c6-29b0-4c89-ba01-1cf068064222n%40googlegroups.com.

Reply via email to