Skip to content

Instantly share code, notes, and snippets.

@leonardocintra
Last active March 14, 2017 15:32
Show Gist options
  • Save leonardocintra/f24405f2b8deddf2c0406f99513da97c to your computer and use it in GitHub Desktop.
Save leonardocintra/f24405f2b8deddf2c0406f99513da97c to your computer and use it in GitHub Desktop.
Model Product and Imagens
from django.db import models
from django.db.models import permalink
from django.core.urlresolvers import reverse
from cloudinary.models import CloudinaryField
class Product(models.Model):
name = models.CharField('Nome', max_length=100)
slug = models.SlugField('Identificador', max_length=100, help_text='identificador baseado no titulo', unique=True)
description = models.TextField('Descrição', blank=True)
price = models.DecimalField('Preço', decimal_places=2, max_digits=8)
created = models.DateField('Criado em', auto_now_add=True)
modified = models.DateField('Modificado em', auto_now=True)
def __str__(self):
return self.name
class Meta:
verbose_name = 'Produto'
verbose_name_plural = 'Produtos'
ordering = ['name']
class ProductImage(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='images')
image = CloudinaryField('Imagem', blank=True, null=True)
description = models.CharField('Descrição', max_length=200, blank=True, default='')
def __str__ (self):
return self.product.name
class Meta:
verbose_name = 'Imagem Produto'
verbose_name = 'Imagens do produto'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment