Last active
February 24, 2017 04:39
-
-
Save bumi/c9eabdb8ae6270d02fd70da1a0f7b445 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from peewee import CharField, TextField, ForeignKeyField | |
from peewee import Model, SqliteDatabase | |
import post # !!!! imports post which imports blog | |
class Blog(Model): | |
title = CharFiled() | |
body = TextField() | |
def import_posts(self, backup): | |
for p in backup: | |
Post.from_backup(self, backup) # !!! requires the post class | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from peewee import CharField, TextField, ForeignKeyField | |
from peewee import Model, SqliteDatabase | |
import blog # !!!! imports blog which imports post | |
class Post(Model): | |
blog = ForeignKeyField(Blog, related_name='posts') # !!!! requires the blog class | |
title = CharFiled() | |
body = TextField() | |
@classmethod | |
def from_backup(blog, backup): | |
p = Post(backup) | |
p.blog = blog | |
p.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment