from django.db import models
from django.contrib.auth.models import User

class MediaUpload(models.Model):
    title = models.CharField(max_length=255, blank=True)
    image = models.ImageField(upload_to='uploads/')
    measurements = models.CharField(max_length=255, blank=True)
    uploaded_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title or str(self.uploaded_at)

class Rating(models.Model):
    media_upload = models.ForeignKey(MediaUpload, on_delete=models.CASCADE, related_name='ratings')
    score = models.IntegerField(choices=[(i, str(i)) for i in range(1, 6)])
    comment = models.TextField(blank=True)
    rater = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f'{self.media_upload.title or self.media_upload.id} - {self.score}'