Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active January 12, 2020 01:57
Show Gist options
  • Save walison17/4c8eb57fea87912d606eff509b52fd02 to your computer and use it in GitHub Desktop.
Save walison17/4c8eb57fea87912d606eff509b52fd02 to your computer and use it in GitHub Desktop.
from datetime import date
from django.db import models
class EmpresaContratada(models.Model):
nome_empresa = models.CharField(max_length=50, blank=False, null=True)
contrato_sap = models.CharField(max_length=20, blank=False, null=True)
data_inicio_contrato = models.DateField(blank=False, null=True)
data_termino_contrato = models.DateField(blank=False, null=True)
slug = models.SlugField(max_length=50, blank=False, null=True, unique=True, default='page-slug')
@property
def status(self):
if self.data_termino_contrato > date.today():
return 'Contrato Vigente'
else:
return 'Contrato Inativo'
def __str__(self):
return self.nome_empresa
def save(self, *args, **kwargs):
if not self.id:
self.slug = uuid4()
super().save(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment