db = PostgresqlDatabase('parttest')
class Base(Model):
class Meta:
database = db
class Document(Base):
# I believe it is necessary to do it this way vs using SERIAL.
id = IntegerField(sequence='document_id_seq', index=True)
name = CharField()
is_reviewed = BooleanField()
class Meta:
table_settings = 'PARTITION BY LIST (is_reviewed)'
# Doc subclasses for accessing partitions directly.
class DocumentReviewed(Document):
class Meta:
table_name = 'document_reviewed'
class DocumentUnreviewed(Document):
class Meta:
table_name = 'document_unreviewed'
db.create_tables([Document])
# Create the partitions.
db.execute_sql('create table document_reviewed partition of document '
'for values in (true)')
db.execute_sql('create table document_unreviewed partition of document '
'for values in (false)')
1条答案
按热度按时间dgtucam11#
我在我的scrap目录中找到了一些可能对你有帮助的代码--这里我有一个文档表,它被划分为已审查/未审查的文档(基于“is_reviewed”列):