diff --git a/.gitignore b/.gitignore index 020de9f..a630c4f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ # environment variables .env +# Migrations +**/migrations + # Node artifact files node_modules/ dist/ diff --git a/README.md b/README.md index 44b9240..cf882e5 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,13 @@ This README aims to document functionality of backend as well as required steps - Clone repository: `git clone git@bitbucket.org:enreda/back-latienda.git` -- From inside the project's folder: +- Create file `.env` from `example.env` and populate fields correctly + +From inside the project's folder: +- Make migrations: ``` python manage.py makemigrations core companies products history stats python migrate - ``` - +- Start server in development mode: `python manage.py runserver` diff --git a/back_latienda/settings/base.py b/back_latienda/settings/base.py index 7401821..10a3aa2 100644 --- a/back_latienda/settings/base.py +++ b/back_latienda/settings/base.py @@ -100,6 +100,8 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] +AUTH_USER_MODEL = 'core.CustomUser' + # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ diff --git a/companies/migrations/__init__.py b/companies/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/core/models.py b/core/models.py index 71a8362..bd48b8d 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,61 @@ from django.db import models +from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager +from django.contrib.auth.models import PermissionsMixin + # Create your models here. +class UserManager(BaseUserManager): + use_in_migrations = True + + def _create_user(self, email, password, **extra_fields): + """ + Creates and saves a User with the given email and password. + """ + if not email: + raise ValueError('The given 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_user(self, email, password=None, **extra_fields): + extra_fields.setdefault('is_superuser', False) + return self._create_user(email, password, **extra_fields) + + def create_superuser(self, email, password, **extra_fields): + extra_fields.setdefault('is_superuser', True) + extra_fields.setdefault('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 CustomUser(AbstractBaseUser, PermissionsMixin): + + email = models.EmailField('Dirección de email', unique=True) + full_name = models.CharField('Nombre completo', max_length=100, blank=True) + role = models.CharField('Rol', max_length=100, blank=True, null=True) + notify = models.BooleanField('Notificar', default=False, null=True) + provider = models.CharField('Proveedor', max_length=1000, blank=True, null=True) # red social de registro + email_verified = models.BooleanField('Email verificado', default=False, null=True) + company = None # models.ForeignKey(Empresa, null=True, on_delete=models.DO_NOTHING) + + is_active = models.BooleanField('Activo', default=True) + is_staff = models.BooleanField('Empleado',default=False ) + + modified = models.DateTimeField(auto_now=True, null=True, blank=True) + created = models.DateTimeField(auto_now_add=True, null=True, blank=True) + last_visit = models.DateTimeField(auto_now=True) + + objects = UserManager() + + USERNAME_FIELD = 'email' + REQUIRED_FIELDS = [] + + class Meta: + verbose_name = 'Usuario' + verbose_name_plural = 'Usuarios' + diff --git a/history/migrations/__init__.py b/history/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/products/migrations/__init__.py b/products/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/stats/migrations/__init__.py b/stats/migrations/__init__.py deleted file mode 100644 index e69de29..0000000