from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
# Create your models here.
class Post(models.Model):
    STATUS_CHOICES=(('draft','draft'),('published','Published'))
    title=models.CharField(max_length=64)
    slug=models.SlugField(max_length=64,unique_for_date="publish")
    #author=models.ForeignKey(User,related_name='blog_posts', on_delete=models.CASCADE)
    author = models.OneToOneField(User, on_delete=models.CASCADE)
    body=models.TextField()
    publish=models.DateTimeField(default=timezone.now)
    created=models.DateTimeField(auto_now=True)
    updated=models.DateTimeField(auto_now=True)
    status=models.CharField(max_length=10,choices=STATUS_CHOICES,default="draft")



    class Meta:
        ordering=("-publish",)

    def __str__(self):
        return self.title


    def get_absolute_url(self):
            #return reverse ('post_detail',args=[self.id ])
            return f'/post/{self.slug}/'
