Skip to content

Instantly share code, notes, and snippets.

@alfonsokim
Created April 22, 2020 15:17
Show Gist options
  • Save alfonsokim/310607f70773ea4bc49b725e0b9104e9 to your computer and use it in GitHub Desktop.
Save alfonsokim/310607f70773ea4bc49b725e0b9104e9 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import uuid
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from django.utils import timezone
from django.contrib.auth.models import AbstractUser, Group
# =======================================================================================
class CareersModel(models.Model):
id = models.BigAutoField(primary_key=True, null=False, blank=False)
api_id = models.UUIDField(null=False, blank=False, default=uuid.uuid4, editable=False, db_index=True)
created_dt = models.DateTimeField(null=False, blank=False, default=timezone.now)
updated_dt = models.DateTimeField(null=True, blank=True)
# -----------------------------------------------------------------------------------
def save(self, *args, **kwargs):
if self.pk: # Actualizar el campo updated_dt cuando se hace un update
self.updated_dt = timezone.now()
super(CareersModel, self).save(*args, **kwargs) # jamasmente nunca never eliminar esta linea
# -----------------------------------------------------------------------------------
class Meta:
abstract = True
# =======================================================================================
class CareersUser(AbstractUser, CareersModel):
""" If you’re starting a new project, it’s highly recommended to set up a custom user model,
even if the default User model is sufficient for you. This model behaves identically to the
default user model, but you’ll be able to customize it in the future if the need arises
https://docs.djangoproject.com/en/1.11/topics/auth/customizing/
"""
USER_TYPE_STUDENT, USER_TYPE_EMPLOYEER, USER_TYPE_MENTOR = range(3)
USER_TYPES = (
(USER_TYPE_STUDENT, 'Estudiante'),
(USER_TYPE_EMPLOYEER, 'Empresa'),
(USER_TYPE_MENTOR, 'Mentor')
)
user_type = models.SmallIntegerField(null=False, blank=False, default=USER_TYPE_STUDENT, choices=USER_TYPES)
# ----------------------------------------------------------------------------------
class Meta:
db_table = 'careers_user'
verbose_name = 'Usuario'
verbose_name_plural = 'Usuarios'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment