forked from evride/repables-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
168 lines (151 loc) · 6.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from peewee import *
from datetime import datetime
from config import DATABASE
from playhouse.migrate import *
# user = User.objects.create_user('john', '[email protected]', 'johnpassword')
# Create your models here.
pg_db = PostgresqlDatabase(DATABASE['NAME'], user=DATABASE['USER'], password=DATABASE['PASSWORD'], host=DATABASE['HOST'], port=DATABASE['PORT'], autorollback=True)
migrator = PostgresqlMigrator(pg_db)
class User(Model):
# user_id = models.AutoField(primary_key=True, auto_created=True)
username = CharField(max_length=64, unique=True)
email = CharField(max_length=128, unique=True)
password = CharField(max_length=255, default='')
fullname = CharField(max_length=128, null=True)
location = CharField(max_length=128, null=True)
company = CharField(max_length = 128, null=True)
biography = TextField(null=True)
website = TextField(null=True)
birthdate = DateTimeField(null=True)
email_public = BooleanField(default=False)
display_birthday = BooleanField(default=False)
hide_inappropriate = BooleanField(default=True)
enabled = BooleanField(default=False)
type = CharField(max_length=11, default="user") #EnumField('administrator', 'moderator', 'user')
remote_address = CharField(max_length=39, null=True)
deleted_at = DateTimeField(null=True)
created_at = DateTimeField(default=datetime.now)
updated_at = DateTimeField(default=datetime.now)
class Meta:
database = pg_db
db_table = "users"
def __str__(self):
return self.username
class Item(Model):
user = ForeignKeyField(User)
revision_id = IntegerField(default=1)
name = CharField(max_length=255)
description = TextField(null=True)
instructions = TextField(null=True)
tags = TextField(null=True)
license = CharField(max_length=10) #EmunField
version = CharField(max_length=50)
flagged_at = DateTimeField(null=True)
deleted_at = DateTimeField(null=True)
created_at = DateTimeField(default=datetime.now)
updated_at = DateTimeField(default=datetime.now)
class Meta:
database = pg_db
db_table = "items"
def __str__(self):
return self.name
class ItemRevision(Model):
item = ForeignKeyField(Item, null=True)
user = ForeignKeyField(User)
name = CharField(max_length=255, default="")
description = TextField(null=True, default="")
instructions = TextField(null=True, default="")
tags = TextField(null=True, default="")
license = CharField(max_length=10, default="") #Enum
version = CharField(max_length=50, default="")
deleted_at = DateTimeField(null=True)
created_at = DateTimeField(default=datetime.now)
updated_at = DateTimeField(default=datetime.now)
class Meta:
database = pg_db
db_table = "item_revisions"
def __str__(self):
return self.name
class ItemImage(Model):
revision_id = IntegerField()
path = CharField(max_length=255, default ="")
upload_id = IntegerField()
width = IntegerField()
height = IntegerField()
type = CharField(max_length=64, default ="")
class Meta:
database = pg_db
db_table = "item_images"
def __str__(self):
return self.type
class ItemUpload(Model):
uploader = ForeignKeyField(User, null=True)
file_location = CharField(max_length=128)
filename = CharField(max_length=256)
file_extension = CharField(max_length=16, null=True) #adding the nullable for testing
size = IntegerField()#filesize Number (file size in number of bytes)
mimetype = CharField(max_length=64)#mimetype varchar(64) NULLABLE (ex: image/png)
revision_id = ForeignKeyField(ItemRevision)
#type varchar(1) NULLABLE (either "primary", "secondary") //define it but mostly ignore for now
#hash String(40) NULLABLE (file hash, md5 ) //define but can ignore for now
#enabled Boolean
#deleted Boolean
#date_uploaded Timestamp
created_at = DateTimeField(default=datetime.now)
updated_at = DateTimeField(default=datetime.now)
#remote_address varchar(39)id #adding the nullable for testing
class Meta:
database = pg_db
db_table = "item_uploads"
def __str__(self):
return self.filename
class ItemView(Model):
item = ForeignKeyField(Item)
revision = ForeignKeyField(ItemRevision)
user = ForeignKeyField(User, null = True)
timestamp = DateTimeField(default=datetime.now)
remote_address = CharField(max_length = 64)
class Meta:
database = pg_db
db_table = "item_views"
class File(Model):
item = ForeignKeyField(Item, null = True)
revision = ForeignKeyField(ItemRevision, null = True)
name = CharField(max_length = 255)
downloadable = BooleanField(default=False)
sort_order = IntegerField()
render = BooleanField(default=True)
preview = BooleanField(default=True)
class Meta:
database = pg_db
db_table = "files"
class Download(Model):
item = ForeignKeyField(Item, null=True)
revision = ForeignKeyField(ItemRevision, null=True)
file = ForeignKeyField(File, null=True)
user = ForeignKeyField(User, null=True)
created_at = DateTimeField(default=datetime.now)
class Meta:
database = pg_db
db_table = "downloads"
class PasswordReset(Model):
user = ForeignKeyField(User)
reset_key = CharField(max_length=32)
created_at = DateTimeField(default=datetime.now)
class Meta:
database = pg_db
db_table = "reset_passwords"
class Upload(Model):
user = ForeignKeyField(User)
revision = ForeignKeyField(ItemRevision, null=True)
file_location = CharField(max_length=256)
filename = CharField(max_length=256)
file_extension = CharField(max_length=10)
filesize = IntegerField()
mimetype = CharField(max_length=128)
hash = CharField(max_length=256)
remote_address = CharField(max_length=39)
uploaded_at = DateTimeField(default=datetime.now)
class Meta:
database = pg_db
db_table = "uploads"