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?
On Sun, 4 Apr 2021 at 07:00, 'Amitesh Sahay' via Django users <django-users@googlegroups.com> wrote:
--Hello Manuel,Try the below. Recently I have worked on custom user model:see if these changes make any difference.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 userRegards,AmiteshOn Saturday, 3 April, 2021, 10:24:52 pm IST, Manuel Buri <manuel.buri@gmail.com> 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 modelsfrom django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixinfrom django.contrib.auth.models import Userfrom organization.models import Organizationclass 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 userdef 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 = Trueuser.is_staff = Trueuser.is_superuser = Trueuser.save(using=self._db)return userclass 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 fieldfirst_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 employeesorganization = 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 permissionsdef 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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/38882988-f54d-4830-9cbd-9b9ad49349c0n%40googlegroups.com.
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1261334457.2585167.1617512381261%40mail.yahoo.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/CACx7KORqS1QkzdT98RbyzaFCahohk8M%2BeLkpomj5%3DTmMK_axXQ%40mail.gmail.com.

No comments:
Post a Comment