from django.db import models
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify
from django.shortcuts import reverse
from django.conf import settings
from ckeditor.fields import RichTextField

# Create your models here.
class Category(models.Model):
    name        = models.CharField(max_length=50,unique=True)
    description = models.TextField()

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = "kategori"

    def save(self,*args, **kwargs):
        return super().save(*args, **kwargs)

class Slide(models.Model):
    """
    Slides yang akan ditampilkan di banner
    """
    DRAFT = 1
    PUBLISHED = 2
    CONTENT_STATUS_CHOICES = [
        (DRAFT, 'Draft'),
        (PUBLISHED, 'Published'),
    ]

    category = models.ForeignKey("category",on_delete=models.SET_NULL,null=True,blank=True)
    title = models.CharField(('Title'), max_length=200)
    show_title = models.BooleanField(("Show title"),default=True)
    cta = models.CharField(('Call to action'),max_length=250,blank=True, null=True)
    link_url = models.CharField(('Link'),max_length=200, blank=True, null=True)
    image = models.FileField(("Image"),upload_to=settings.BANNER,max_length=255, null=True, blank=True)
    status = models.SmallIntegerField(("Status"), choices=CONTENT_STATUS_CHOICES, default=DRAFT)
    featured = models.BooleanField(default=False)

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs): 
        return super().save(*args, **kwargs)

    def delete(self, *args, **kwargs):
        """
        Deletes associated media
        """
        self.image.delete()
        super(Slide, self).delete(*args, **kwargs)

    class Meta:
        #verbose_name = ("Slide")
        verbose_name_plural = ("Slide")