from django.db import models
from django.forms import ValidationError

# Create your models here.

class HeroSection(models.Model):
    video_url = models.URLField(max_length=500, help_text="Input youtube link here")
    thumbnail_image = models.ImageField(upload_to='hero/', help_text="Upload thumbnail image")
    created_at = models.DateTimeField(auto_now_add = True);
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = "Hero Section"
        verbose_name_plural = "Hero Section"
    
    def save(self, *args, **kwargs):
        if not self.pk and HeroSection.objects.exists():
            raise ValidationError('Kindly update existing data')
        return super(HeroSection, self).save(*args, **kwargs)




    def __str__(self):
        return self.video_url
