Skip to content

Instantly share code, notes, and snippets.

@alisonamerico
Last active August 2, 2020 15:09
Show Gist options
  • Save alisonamerico/5435adaa23a91a79e48ddaf393cd1e2f to your computer and use it in GitHub Desktop.
Save alisonamerico/5435adaa23a91a79e48ddaf393cd1e2f to your computer and use it in GitHub Desktop.
Descrição:
Uma **Demanda de Peças** é composta por:
Descrição da peça que está sendo solicitada
Endereço de Entrega (considere que estamos trabalhando no Brasil)
Informações de Contato
Anunciante (Usuário Dono)
Status de Finalização (Aberta ou Finalizada)
==================================================================================
# api/models.py
from django.db import models
from django.contrib.auth import get_user_model
class Anunciante(models.Model):
name = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) <-- Custom User Django
phone_number = models.CharField(max_length=15)
email = models.EmailField(max_length=254)
created = models.DateTimeField('Created in', auto_now_add=True)
modified = models.DateTimeField('Modified in', auto_now=True)
class Meta:
verbose_name = 'Anunciante'
verbose_name_plural = 'Anunciantes'
ordering = ['-created']
def __str__(self):
"""A string representation of the model."""
return self.name
class DemandaDePecas(models.Model):
STATUS_FINALIZACAO_CHOICES = [
('ABERTA', 'Aberta'),
('FINALIZADA', 'Finalizada'),
]
descricao_peca = models.CharField(max_length=150)
endereco_entrega = models.CharField(max_length=150)
anunciante = models.ForeignKey('Anunciante', on_delete=models.CASCADE)
status_finalizacao = models.CharField(max_length=20, choices=STATUS_FINALIZACAO_CHOICES)
created = models.DateTimeField('Created in', auto_now_add=True)
modified = models.DateTimeField('Modified in', auto_now=True)
class Meta:
verbose_name = 'DemandaDePeca'
verbose_name_plural = 'DemandaDePecas'
ordering = ['-created']
def __str__(self):
"""A string representation of the model."""
return self.descricao_peca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment