-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
55 lines (41 loc) · 1.65 KB
/
Copy pathmodels.py
File metadata and controls
55 lines (41 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from markdown import markdown
from django.db import models
from django.utils import timezone
from django.urls import reverse_lazy
class Category(models.Model):
category_text = models.CharField(max_length=100)
def __str__(self):
return self.category_text
class Mata:
verbose_name_plural = 'categories'
class Tag(models.Model):
tag_text = models.CharField(max_length=50)
def __str__(self):
return self.tag_text
class Post(models.Model):
tags = models.ManyToManyField(Tag)
category = models.ForeignKey(Category, on_delete=models.CASCADE, default=0)
headline = models.CharField(max_length=200)
markdown_text = models.TextField('markdown content')
html = models.TextField('html text', editable=False)
publication_date = models.DateTimeField(editable=False, default=timezone.now)
modification_date = models.DateTimeField(editable=False)
def save(self):
self.modification_date = timezone.now()
self.html = markdown(self.markdown_text)
super(self.__class__, self).save()
def __str__(self):
return self.headline
def get_absolute_url(self):
return reverse_lazy('post', kwargs={'pk':self.pk})
class Meta:
ordering = ['-publication_date', ]
class Comment(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField()
content = models.TextField()
date = models.DateTimeField(editable=False, default=timezone.now)
reply = models.OneToOneField('self', on_delete=models.CASCADE, blank=True, null=True)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
def __str__(self):
return self.name