
from django.db import models
from homepage.models import WidgetUser
from django.urls import reverse

# Create your models here.
class Announcement(models.Model):
    announcement_title = models.CharField(max_length=50)
    announcement_body = models.TextField(max_length=1500)
    pub_date = models.DateTimeField("date published", auto_now_add=True)
    pub_date.editable = True
    author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
    announcement_image = models.ImageField(null = True, blank = True, upload_to = "announcements/")

    def __str__(self):
        return self.announcement_title
    
    def get_absolute_url(self):
        return u'%d/details' % self.pk

class Reaction(models.Model):
    LIKE = "Like"
    LOVE = "Love"
    ANGRY = "Angry"
    REACTION_CHOICES = [
        (LIKE, 'Like'),
        (LOVE, 'Love'),
        (ANGRY, 'Angry'),
    ]
    announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
    reaction_name = models.CharField(
        max_length=5,
        choices=REACTION_CHOICES,
        default=LIKE,
    )
    tally = models.IntegerField(default=0)