-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
36 lines (30 loc) · 1.05 KB
/
model.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
import peewee
import datetime
from core import db
class Category(db.Model):
name = peewee.CharField()
slug = peewee.CharField()
class Meta:
table_name = "category"
class Post(db.Model):
title = peewee.CharField()
slug = peewee.CharField(index=True, max_length=100)
category = peewee.ForeignKeyField(Category, backref='posts')
content = peewee.TextField()
readnum = peewee.IntegerField(default=0)
tags = peewee.CharField(null=True)
slug = peewee.CharField(null=True)
created = peewee.DateTimeField(default=datetime.datetime.now)
# @cached_property
# def prev(self):
# posts = Post.select().where(Post.created < self.created)\
# .order_by(Post.created)
# return posts.get() if posts.exists() else None
# @cached_property
# def next(self):
# posts = Post.select().where(Post.created > self.created)\
# .order_by(Post.created)
# return posts.get() if posts.exists() else None
class Meta:
table_name = "posts"
order_by = ('-created',)