Skip to content

Instantly share code, notes, and snippets.

@fandrefh
Created May 22, 2015 11:29
Show Gist options
  • Save fandrefh/8f7d1bb5677857031c20 to your computer and use it in GitHub Desktop.
Save fandrefh/8f7d1bb5677857031c20 to your computer and use it in GitHub Desktop.
from django.db import models
from localflavor.br.br_states import STATE_CHOICES
# Create your models here.
class Restaurante(models.Model):
restaurante = models.CharField(u'Restaurante', max_length=255)
endereco = models.CharField(u'Endereço', max_length=255)
numero = models.CharField(u'Número', max_length=20)
cep = models.CharField(u'CEP', max_length=10, help_text='Formato: 00.000-000')
bairro = models.CharField(u'Bairro', max_length=50)
cidade = models.CharField(u'Cidade', max_length=50)
estado = models.CharField(u'Estado', max_length=2, choices=STATE_CHOICES)
gerente = models.CharField(u'Responsável/Gerente', max_length=255)
telefone = models.CharField(u'Telefone', max_length=14, help_text='(00)00000-0000')
cardapio = models.ForeignKey('Cardapio')
dt_cadastro = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.restaurante
class Meta:
ordering = ('-dt_cadastro',)
verbose_name='Restaurante'
verbose_name_plural='Restaurantes'
class Produto(models.Model):
UNIDADE_CHOICES = (
('GRAMA', 'GRAMA'),
('KG', 'KG'),
('LT', 'LT'),
('ML', 'ML'),
)
produto = models.CharField(u'Produto', max_length=100)
descricao = models.TextField(u'Descrição/Acompanha')
preco_normal = models.DecimalField(u'Preço normal R$', max_digits=9, decimal_places=2)
preco_promocao = models.DecimalField(u'Preço promocional R$', max_digits=9, decimal_places=2)
peso = models.PositiveIntegerField()
unidade_medida = models.CharField(u'Und de Medida', choices=UNIDADE_CHOICES, max_length=10)
serve_pessoas = models.PositiveIntegerField(u'Quantas Pessoas?', blank=True)
dia_promocao = models.ManyToManyField('DiaPromocao', verbose_name='Dia da Promoção')
foto_produto = models.ImageField(u'Foto produto', upload_to='fotos')
dt_cadastro = models.DateTimeField(auto_now_add=True, auto_now=True)
def __str__(self):
return self.produto
class Meta:
verbose_name='Produto'
verbose_name_plural='Produtos'
class DiaPromocao(models.Model):
dia = models.CharField(u'Dia da semana', max_length=30, help_text='Exemplo: Segunda-feira')
def __str__(self):
return self.dia
class Meta:
ordering = ('id',)
verbose_name='Dia de Promoção'
verbose_name_plural='Dias de Promoção'
class Cardapio(models.Model):
cardapio = models.CharField(u'Nome cardápio', max_length=100)
produto = models.ManyToManyField(Produto, related_name='produtos')
obs = models.TextField(u'Observação', null=True, blank=True)
def produtos(self):
return ", ".join([p.produto for p in self.produto.all()])
def __str__(self):
return self.cardapio
class Meta:
verbose_name='Cardápio'
verbose_name_plural='Cardápios'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment