def get_blog_detail(cls, blog_id): blog = cls.get(cls.id == blog_id) blogtags = BlogTags.get(BlogTags.blog_id == blog.id) tag = Tags.get(Tags.id == blogtags.tags_id).tag blogcategory = BlogCategory.get(BlogCategory.blog_id == blog_id) category = Category.get(Category.id == blogcategory.category_id).category return blog, tag, category
def get_blog_by_tag(cls, tag): # tag_id = Tags.select(Tags.id).order_by(Tags.tag == tag, Tags.id.desc())[0].id - 1 tag_id = Tags.get(Tags.tag == tag).id blogs_ids = BlogTags.select(BlogTags.blog_id).where(BlogTags.tags_id == tag_id) return cls.select().filter(cls.id << blogs_ids)
def get_tag(cls, blog_id): tag_id = cls.get(cls.blog_id == blog_id).tags_id return Tags.get(Tags.id == tag_id).tag