Skip to content

Instantly share code, notes, and snippets.

@bumi
Last active February 24, 2017 04:39
Show Gist options
  • Save bumi/c9eabdb8ae6270d02fd70da1a0f7b445 to your computer and use it in GitHub Desktop.
Save bumi/c9eabdb8ae6270d02fd70da1a0f7b445 to your computer and use it in GitHub Desktop.
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
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