-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
53 lines (37 loc) · 1.46 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
import peewee
from settings import db
from peewee_extra_fields import SimplePasswordField
from datetime import datetime
# loop = asyncio.new_event_loop()
__all__ = ["User", "UserTest", "Question", "Answer", "UserAnswer"]
class BaseModel(peewee.Model):
"""A base model that will use our Postgresql database"""
class Meta:
database = db
class User(BaseModel):
username = peewee.CharField(unique=True)
password = SimplePasswordField('weqwe')
first_name = peewee.CharField(null=True)
last_name = peewee.CharField(null=True)
age = peewee.IntegerField(null=True)
is_superuser = peewee.BooleanField(default=False)
class UserTest(BaseModel):
name = peewee.CharField()
is_public = peewee.BooleanField(default=True)
class Question(BaseModel):
test_ = peewee.ForeignKeyField(UserTest)
order = peewee.IntegerField(default=10)
text = peewee.CharField()
def get_answer(self):
return Answer.select().where(Answer.quest == self)
class Answer(BaseModel):
quest = peewee.ForeignKeyField(Question)
is_correct = peewee.BooleanField(default=False)
text = peewee.CharField()
class UserAnswer(BaseModel):
resp_date = peewee.DateTimeField(default=datetime.now())
user_ = peewee.ForeignKeyField(User)
quest = peewee.ForeignKeyField(Question)
answer = peewee.BooleanField(null=True)
# objects = Manager(db, loop=loop)
# objects.database.allow_sync = False # this will raise AssertionError on ANY sync call