-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
75 lines (60 loc) · 1.9 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
from peewee import PostgresqlDatabase, Model, TextField, DateTimeField, ForeignKeyField, BooleanField, IntegerField
from datetime import datetime
from config import Config
import os
import urllib.parse
db_parsed_url = urllib.parse.urlparse(Config.DATABASE_URL)
username = db_parsed_url.username
password = db_parsed_url.password
database = db_parsed_url.path[1:]
hostname = db_parsed_url.hostname
postgres_db = PostgresqlDatabase(
database=database,
user=username,
password=password,
host=hostname,
autocommit=True,
autorollback=True)
class User(Model):
name = TextField(unique=True)
admin = BooleanField(default=False)
password = TextField()
active = BooleanField(default=True)
created_at = DateTimeField(default=datetime.now)
updated_at = DateTimeField(default=datetime.now)
def get_id(self):
return str(self.id)
@property
def is_active(self):
return self.active
@property
def is_authenticated(self):
return True
@property
def is_anonymous(self):
return False
class Meta:
database = postgres_db
class Post(Model):
title = TextField()
description = TextField()
content = TextField()
tags = TextField()
slug = TextField()
posted_by = ForeignKeyField(User, related_name='posts')
created_at = DateTimeField(default=datetime.now)
updated_at = DateTimeField(default=datetime.now)
class Meta:
database = postgres_db
class Settings(Model):
blog_title = TextField()
initialized = BooleanField()
icon_1_link = TextField()
icon_1_icon_type = TextField()
icon_2_link = TextField()
icon_2_icon_type = TextField()
posts_per_page = IntegerField()
number_of_recent_posts = IntegerField()
max_synopsis_chars = IntegerField()
class Meta:
database = postgres_db