diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 84088f6525..aa0669ffe0 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -110,8 +110,11 @@ class Group(models.Model): messages. """ name = models.CharField(_('name'), max_length=80, unique=True) - permissions = models.ManyToManyField(Permission, - verbose_name=_('permissions'), blank=True) + permissions = models.ManyToManyField( + Permission, + verbose_name=_('permissions'), + blank=True, + ) objects = GroupManager() @@ -197,18 +200,33 @@ class PermissionsMixin(models.Model): A mixin class that adds the fields and methods necessary to support Django's Group and Permission model using the ModelBackend. """ - is_superuser = models.BooleanField(_('superuser status'), default=False, - help_text=_('Designates that this user has all permissions without ' - 'explicitly assigning them.')) - groups = models.ManyToManyField(Group, verbose_name=_('groups'), - blank=True, help_text=_('The groups this user belongs to. A user will ' - 'get all permissions granted to each of ' - 'their groups.'), - related_name="user_set", related_query_name="user") - user_permissions = models.ManyToManyField(Permission, - verbose_name=_('user permissions'), blank=True, + is_superuser = models.BooleanField( + _('superuser status'), + default=False, + help_text=_( + 'Designates that this user has all permissions without ' + 'explicitly assigning them.' + ), + ) + groups = models.ManyToManyField( + Group, + verbose_name=_('groups'), + blank=True, + help_text=_( + 'The groups this user belongs to. A user will get all permissions ' + 'granted to each of their groups.' + ), + related_name="user_set", + related_query_name="user", + ) + user_permissions = models.ManyToManyField( + Permission, + verbose_name=_('user permissions'), + blank=True, help_text=_('Specific permissions for this user.'), - related_name="user_set", related_query_name="user") + related_name="user_set", + related_query_name="user", + ) class Meta: abstract = True @@ -274,27 +292,38 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin): Username, password and email are required. Other fields are optional. """ - username = models.CharField(_('username'), max_length=30, unique=True, - help_text=_('Required. 30 characters or fewer. Letters, digits and ' - '@/./+/-/_ only.'), + username = models.CharField( + _('username'), + max_length=30, + unique=True, + help_text=_('Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.'), validators=[ - validators.RegexValidator(r'^[\w.@+-]+$', - _('Enter a valid username. ' - 'This value may contain only letters, numbers ' - 'and @/./+/-/_ characters.'), 'invalid'), + validators.RegexValidator( + r'^[\w.@+-]+$', + _('Enter a valid username. This value may contain only ' + 'letters, numbers ' 'and @/./+/-/_ characters.') + ), ], error_messages={ 'unique': _("A user with that username already exists."), - }) + }, + ) first_name = models.CharField(_('first name'), max_length=30, blank=True) last_name = models.CharField(_('last name'), max_length=30, blank=True) email = models.EmailField(_('email address'), blank=True) - is_staff = models.BooleanField(_('staff status'), default=False, - help_text=_('Designates whether the user can log into this admin ' - 'site.')) - is_active = models.BooleanField(_('active'), default=True, - help_text=_('Designates whether this user should be treated as ' - 'active. Unselect this instead of deleting accounts.')) + is_staff = models.BooleanField( + _('staff status'), + default=False, + help_text=_('Designates whether the user can log into this admin site.'), + ) + is_active = models.BooleanField( + _('active'), + default=True, + help_text=_( + 'Designates whether this user should be treated as active. ' + 'Unselect this instead of deleting accounts.' + ), + ) date_joined = models.DateTimeField(_('date joined'), default=timezone.now) objects = UserManager()