def _get_posts_by_tag(cls, identifier): if not identifier: return [] if not is_numeric(identifier): tag = Tag.get_by_name(identifier) if not tag: return identifier = tag.id at_ids = cls.query.with_entities( cls.post_id).filter(cls.tag_id == identifier).all() query = Post.query.filter(Post.id.in_(id for id, in at_ids)).order_by( Post.id.desc()) return query
def get(cls, identifier): if is_numeric(identifier): return cls.cache.get(identifier) # get post via title return cls.cache.filter(title=identifier).first()
def get(cls, identifier): post = cls.objects.filter(title=identifier).first() if post: return post if is_numeric(identifier): return cls.objects.get(pk=identifier)
def get(cls, identifier): return super().get(identifier) if is_numeric(identifier) \ else cls.get_by_title(identifier)