diff --git a/core/models.py b/core/models.py index 71a8362..68f3411 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,48 @@ from django.db import models -# Create your models here. +from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +class MyUserManager(BaseUserManager): + def create_user(self, email, password=None, **extra_fields): + if not email: + raise ValueError(_('The Email must be set')) + email = self.normalize_email(email) + user = self.model(email=email, **extra_fields) + user.set_password(password) + user.save(using=self._db) + return user + + def create_superuser(self, email, 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(email, password, **extra_fields) + +class MyUser(AbstractBaseUser, PermissionsMixin): + email = models.EmailField(_('email address'), unique=True) + first_name = models.CharField(_('first name'), max_length=30, blank=True) + last_name = models.CharField(_('last name'), max_length=150, blank=True) + is_staff = models.BooleanField(_('staff status'), default=False) + is_active = models.BooleanField(_('active'), default=True) + + objects = MyUserManager() + + USERNAME_FIELD = 'email' + REQUIRED_FIELDS = [] + + def __str__(self): + return self.email + + def get_full_name(self): + full_name = '%s %s' % (self.first_name, self.last_name) + return full_name.strip() + + def get_short_name(self): + return self.first_name diff --git a/izaac/settings.py b/izaac/settings.py index f418b7d..524de5e 100644 --- a/izaac/settings.py +++ b/izaac/settings.py @@ -37,6 +37,8 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "rest_framework", + "core", ] MIDDLEWARE = [ @@ -74,13 +76,16 @@ WSGI_APPLICATION = "izaac.wsgi.application" # https://docs.djangoproject.com/en/4.1/ref/settings/#databases DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'izaac', + 'USER': 'izaac', + 'PASSWORD': 'iz@@cPWD@$5', + 'HOST': 'postgres-service', + 'PORT': '10452', } } - # Password validation # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators diff --git a/requirements.txt b/requirements.txt index 9dcfb88..e45b4ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ django -gunicorn \ No newline at end of file +gunicorn +djangorestframework +psycopg2-binary \ No newline at end of file