2010-11-05 00:03:05 +08:00
|
|
|
from django.db import models
|
2015-10-14 02:25:06 +08:00
|
|
|
from django.utils import timezone
|
2010-11-05 00:03:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Article(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
pub_date = models.DateField()
|
2020-01-19 03:07:25 +08:00
|
|
|
pub_datetime = models.DateTimeField(default=timezone.now)
|
2010-11-05 00:03:05 +08:00
|
|
|
|
|
|
|
categories = models.ManyToManyField("Category", related_name="articles")
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-11-05 00:03:05 +08:00
|
|
|
return self.title
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-11-05 00:03:05 +08:00
|
|
|
class Comment(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
article = models.ForeignKey(Article, models.CASCADE, related_name="comments")
|
2010-11-05 00:03:05 +08:00
|
|
|
text = models.TextField()
|
|
|
|
pub_date = models.DateField()
|
|
|
|
approval_date = models.DateField(null=True)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-11-05 00:03:05 +08:00
|
|
|
return 'Comment to %s (%s)' % (self.article.title, self.pub_date)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-11-05 00:03:05 +08:00
|
|
|
class Category(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|