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):
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now)
    # one author may have multi post but one post only have one author
    # so this is a m2o field

    # to get self function, we should define function before use it.
    author = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.title

    # After finishing post create
    # To let view handle redirect we use reverse to
    # return full url string to route
    # def get_absolute_url(self):
    #     return reverse('post_detail', kwargs={'pk': self.pk})