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

# Create your models here.
class Post(models.Model):
    post_title = models.CharField(max_length=50)
    post_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)
    post_image = models.ImageField(null = True, blank = True, upload_to = "forum/")

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

class Reply(models.Model):
    post = models.ForeignKey(Post, on_delete=models.CASCADE)
    reply_body = models.TextField(max_length=1500)
    author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
    pub_date = models.DateTimeField("date published")
    

    def __str__(self):
        return "Reply from " + self.author.first_name + " " + self.author.last_name
    
    class Meta:
        verbose_name_plural = "Replies"