from django.db import models
from django.utils import timezone

class Year(models.Model):
    year = models.IntegerField(unique=True)
    
    def __str__(self):
        return str(self.year)
    
    class Meta:
        ordering = ['-year']

class Video(models.Model):
    year = models.ForeignKey(Year, on_delete=models.CASCADE, related_name='videos')
    title = models.CharField(max_length=255)
    video_file = models.FileField(upload_to='videos/')
    thumbnail = models.ImageField(upload_to='thumbnails/', blank=True, null=True)
    description = models.TextField(blank=True)
    upload_date = models.DateTimeField(default=timezone.now)
    
    def __str__(self):
        return self.title
    
    class Meta:
        ordering = ['title']
