-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
101 lines (54 loc) · 2.2 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
import uuid
# new models here
class UserModel(models.Model):
name = models.CharField(max_length=120)
email = models.EmailField()
username = models.CharField(max_length=120)
password = models.CharField(max_length=40)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
class SessionToken(models.Model):
user = models.ForeignKey(UserModel)
session_token = models.CharField(max_length=255)
created_on = models.DateTimeField(auto_now_add=True)
is_valid = models.BooleanField(default=True)
def create_token(self):
self.session_token = uuid.uuid4()
class PostModel(models.Model):
user = models.ForeignKey(UserModel)
image = models.FileField(upload_to = 'user_images')
image_url = models.CharField(max_length=255)
caption = models.CharField(max_length=255)
category = models.CharField(max_length=255)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
has_liked = False
@property
def like_count(self):
return len(LikeModel.objects.filter(post=self))
@property
def comments(self):
return CommentModel.objects.filter(post=self).order_by('created_on')
class LikeModel(models.Model):
user = models.ForeignKey(UserModel)
post = models.ForeignKey(PostModel)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
class CommentModel(models.Model):
user = models.ForeignKey(UserModel)
post = models.ForeignKey(PostModel)
comment_text = models.CharField(max_length=555)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
has_upvoted = False
@property
def upvote_count(self):
return len(UpvoteModel.objects.filter(comment=self))
class UpvoteModel(models.Model):
user = models.ForeignKey(UserModel)
comment = models.ForeignKey(CommentModel)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)