-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
55 lines (40 loc) · 1.49 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
from collections import defaultdict
import peewee
from project.db import db
class BaseModel(peewee.Model):
class Meta:
database = db
class User(BaseModel):
user_tg_id = peewee.BigIntegerField(verbose_name='id в Telegram')
class Message(BaseModel):
chat_tg_id = peewee.BigIntegerField(verbose_name='id чата')
message_tg_id = peewee.BigIntegerField(verbose_name='id сообщения')
user_tg_id = peewee.BigIntegerField(verbose_name='id пользователя')
# user = peewee.ForeignKeyField(User, backref='messages')
def get_likes_by_type(self):
query = self.likes.select(Like.type, peewee.fn.COUNT(Like.id).alias('like_count')).group_by(Like.type)
data = defaultdict(int)
for e in query:
data[e.type] = e.like_count
return data
class Like(BaseModel):
message = peewee.ForeignKeyField(Message, backref='likes')
user_tg_id = peewee.BigIntegerField(verbose_name='id пользователя')
# user = peewee.ForeignKeyField(User, backref='likes')
LIKE = 1
DISLIKE = 2
OLD = 3
CLASSIC = 4
TYPE_CHOICES = (
(LIKE, 'Лайк'),
(DISLIKE, 'Дислайк'),
(OLD, 'Баян'),
(CLASSIC, 'Классика'),
)
type = peewee.IntegerField(verbose_name='тип', choices=TYPE_CHOICES)
BUTTON_LABELS = (
(LIKE, '\U0001F44D'),
(DISLIKE, '\U0001F44E'),
(CLASSIC, '\U0001F44D [:||||:]'),
(OLD, '\U0001F44E [:||||:]'),
)