# coding=utf-8

from django.db import models
from django.conf import settings

from apps.foundation.models import Option
from apps.images.models import Images


class Product(models.Model):
    category = models.ForeignKey(Option, verbose_name=u'类别', on_delete=models.PROTECT)
    name = models.CharField(max_length=255, verbose_name=u"名称")
    describe = models.CharField(verbose_name=u'介绍', max_length=500, null=True, blank=True)
    price = models.BigIntegerField(verbose_name=u'价格', default=0)
    enabled = models.BooleanField(verbose_name=u"在用", default=True)
    cover = models.ForeignKey(Images, verbose_name=u'封面图', on_delete=models.PROTECT, related_name=u'product_thumbnail', null=True)
    notes = models.CharField(max_length=500, verbose_name=u"备注", blank=True, null=True)

    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'创建人', editable=False, on_delete=models.PROTECT)
    create_time = models.DateTimeField(verbose_name=u"添加时间", auto_now_add=True, editable=False)

    delete = models.BooleanField(verbose_name=u"删除", default=False, editable=False)

    class Meta:
        db_table = "product"
        verbose_name = u"商品"
        ordering = ('-id',)
        default_permissions = ()


class ProductImg(models.Model):
    product = models.ForeignKey(Product, verbose_name=u'商品', on_delete=models.PROTECT)
    img = models.ForeignKey(Images, verbose_name=u'图片', on_delete=models.PROTECT)

    class Meta:
        db_table = 'product_img'
        verbose_name = u'商品图片'
        ordering = ('-id',)
        default_permissions = ()