from django.db import models

# Create your models here.


class Category(models.Model):
    slug = models.SlugField(max_length=30, primary_key=True)
    name = models.CharField(max_length=50)
    image = models.ImageField(upload_to='categories', blank=True)


    class Meta:
        verbose_name = 'Kategorya'
        verbose_name_plural = 'Kategorya'

    def __str__(self):
        return self.name


class Product(models.Model):
    title = models.CharField(max_length=100)
    description = models.TextField()
    price = models.DecimalField(max_digits=10, decimal_places=2)
    category= models.ForeignKey(Category, on_delete=models.CASCADE,
                                related_name='products')
    create_at = models.DateTimeField(auto_now_add=True)
    image = models.ImageField(upload_to='products', blank=True)


    class Meta:
        verbose_name = 'Producty'
        verbose_name_plural = 'Producty'

    def __str__(self):
        return f'{self.title} Opisanie: {self.description[0:20]}'

