-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.py
54 lines (43 loc) · 1.48 KB
/
models.py
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
from django.contrib.auth import get_user_model
from django.db import models
User = get_user_model()
class Group(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
description = models.TextField()
def __str__(self):
return self.title
class Post(models.Model):
text = models.TextField()
pub_date = models.DateTimeField('Дата публикации', auto_now_add=True)
author = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='posts')
image = models.ImageField(
upload_to='posts/', null=True, blank=True)
group = models.ForeignKey(
Group, on_delete=models.SET_NULL,
related_name="posts", blank=True, null=True
)
def __str__(self):
return self.text
class Comment(models.Model):
author = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='comments')
post = models.ForeignKey(
Post, on_delete=models.CASCADE, related_name='comments')
text = models.TextField()
created = models.DateTimeField(
'Дата добавления', auto_now_add=True, db_index=True)
class Follow(models.Model):
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
verbose_name='Подписчик',
related_name='follower'
)
following = models.ForeignKey(
User,
on_delete=models.CASCADE,
verbose_name='Автор',
related_name='following'
)