forked from DmitriiP/agora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
53 lines (45 loc) · 1.83 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
from django.db import models
from django.contrib.auth.models import User
class BaseItem(models.Model):
"""Abstract class holding common fields."""
# Amount of upvotes
upvotes = models.IntegerField(db_index=True, default=0)
timestamp = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User)
class Meta:
abstract = True
class UserInfo(models.Model):
homepage = models.URLField(default='')
about = models.TextField(default='')
# picture = models.TextField(default='')
location = models.TextField(default='')
age = models.IntegerField(default=0)
user = models.ForeignKey(User, unique=True)
timestamp = models.DateTimeField(auto_now_add=True)
show_email = models.BooleanField(default=False)
class Post(BaseItem):
title = models.TextField(db_index=True)
url = models.URLField(default='')
# XXX Should this or shouldn't be indexed.
text = models.TextField(default='', db_index=True)
class Question(BaseItem):
title = models.TextField(db_index=True)
# XXX Should this or shouldn't be indexed.
text = models.TextField(default='', db_index=True)
class Comment(BaseItem):
post = models.ForeignKey(Post, db_index=True)
text = models.TextField(default='')
depth = models.IntegerField(default=0)
parent = models.IntegerField(default=0, db_index=True)
class Karma(BaseItem):
# This is the most complex item as it implements users karma
# How many posts/comments he did daily, in average.
activity = models.FloatField(default=0.0)
class CommentVotes(models.Model):
user = models.ForeignKey(User)
comment = models.ForeignKey(Comment)
is_positive = models.BooleanField(default=True)
class PostVotes(models.Model):
user = models.ForeignKey(User)
post = models.ForeignKey(Post)
is_positive = models.BooleanField(default=True)