Skip to content

Commit

Permalink
Merge pull request #37 from ernestofgonzalez/fix/createsuperuser
Browse files Browse the repository at this point in the history
Fix `createsuperuser` command
  • Loading branch information
ernestofgonzalez committed Jun 6, 2023
2 parents af91676 + 62cb9e5 commit afac3e0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
Changelog
=========

.. _v_0_4_1:

0.4.1 (2023-06-06)
------------------

* Fixed `createsuperuser` command (:issue:`36`)

.. _v_0_4_0:

0.4.0 (2023-01-27)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = 'Django Rocket'
copyright = '2023, Ernesto F. González'
author = 'Ernesto F. González'
release = '0.4.0'
release = '0.4.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import stripe
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.db import models
from django.utils.functional import cached_property
from phonenumber_field.modelfields import PhoneNumberField
from {{cookiecutter.project_slug}}.utils import default_uuid


class UserManager(BaseUserManager):
def create_user(self, email, password=None, name=None, **extra_fields):
if not email:
raise ValueError('Enter an email address')
if not name:
raise ValueError('Enter a name')
email = self.normalize_email(email)
user = self.model(email=email, name=name, **extra_fields)
user.set_password(password)
user.save()
return user

def create_superuser(self, email, name, password):
user = self.create_user(email, name=name, password=password)
user.is_superuser = True
user.is_staff = True
user.save()
return user


class User(AbstractUser):
uuid = models.CharField(
default=default_uuid, editable=False, unique=True, max_length=255
Expand All @@ -28,6 +48,8 @@ class User(AbstractUser):
null=True, blank=False, max_length=255,
)

objects = UserManager()

USERNAME_FIELD = "email"
REQUIRED_FIELDS = [
"name",
Expand Down

0 comments on commit afac3e0

Please sign in to comment.