from django.db import models
from ckeditor.fields import RichTextField

# Create your models here.

class Article(models.Model):
    author = models.ForeignKey(to="auth.User",on_delete = models.CASCADE,verbose_name="Yazar") #auth.userdan alıcak demek 
    title = models.CharField(max_length=50,verbose_name="Başlık")
    content = RichTextField()
    created_date = models.DateTimeField(auto_now_add=True,verbose_name="Olusturulma Tarihi") #auto_now_add direk olarak o zamanı alır.
    article_image = models.FileField(blank=True,null=True,verbose_name="Makaleye fotograf ekleyin")


    def __str__(self):
        return self.title

    class Meta:
        ordering = ['-created_date']
   
class Comment(models.Model):
    article = models.ForeignKey(to=Article, on_delete= models.CASCADE,verbose_name="Makale", related_name= "comments")
    comment_author = models.CharField(max_length=50,verbose_name="İsminiz")
    comment_content = models.CharField(max_length=200,verbose_name="Yorum")
    comment_date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.article

    class Meta:
        ordering = ['-comment_date']