def _user_has_account(self): blog = Database.find_one('blogs', {'author': self.user}) if blog is not None: self.user_blog = Blog.from_mongo(blog['id']) return True else: return False
def from_mongo(cls, id): blog_data = Database.find_one(collection='blogs', query={'id': id}) return cls(author=blog_data['author'], title=blog_data['title'], description=blog_data['description'], id=blog_data['id'])
def from_mongo(cls, id): # Post.from_mongo('123') post_data = Database.find_one(collection='posts', query={'id': id}) return cls(blog_id=post_data['blog_id'], title=post_data['title'], content=post_data['content'], author=post_data['author'], date=post_data['created_date'], id=post_data['id']) # return a instance of Post class
def from_blog(id): return [ post for post in Database.find(collection='posts', query={'blog_id': id}) ]
def save_to_mongo(self): Database.insert(collection='posts', data=self.json())
import pymongo from basic_template.blog import Blog from basic_template.menu import Menu from basic_template.post import Post from basic_template.database import Database Database.initialize() menu = Menu() menu.run_menu()
def _list_blogs(self): blogs = Database.find(collection='blogs', query={}) for blog in blogs: print("ID: {}, Title: {}, Author: {}".format( blog['id'], blog['title'], blog['author']))