|
@@ -150,22 +150,22 @@ class User(Model):
|
|
|
|
|
|
def get_tags(self) -> List[v.Tag]:
|
|
|
return sorted(
|
|
|
- (t.to_view() for t in self.tags), # type: ignore
|
|
|
+ (t.to_view() for t in self.tags), # type: ignore
|
|
|
key=lambda t: t.name,
|
|
|
)
|
|
|
|
|
|
- def get_related_tags(self, tag: 'Tag') -> List[v.Tag]:
|
|
|
+ def get_related_tags(self, tag: "Tag") -> List[v.Tag]:
|
|
|
# SELECT * from has_tag t1, has_tag t2, link l WHERE t1.link_id == l.id AND t2.link_id == l.id AND t1.id != t2.id AND t1 = self
|
|
|
SelfTag = HasTag.alias()
|
|
|
- query = (HasTag.select(HasTag.tag)
|
|
|
- .join(Link, on=(HasTag.link == Link.id))
|
|
|
- .join(SelfTag, on=(SelfTag.link == Link.id))
|
|
|
- .where((SelfTag.tag == tag) & (SelfTag.id != HasTag.id))
|
|
|
- .group_by(HasTag.tag))
|
|
|
- return sorted(
|
|
|
- (t.tag.to_view() for t in query),
|
|
|
- key=lambda t: t.name,
|
|
|
+ query = (
|
|
|
+ HasTag.select(HasTag.tag)
|
|
|
+ .join(Link, on=(HasTag.link == Link.id))
|
|
|
+ .join(SelfTag, on=(SelfTag.link == Link.id))
|
|
|
+ .where((SelfTag.tag == tag) & (SelfTag.id != HasTag.id))
|
|
|
+ .group_by(HasTag.tag)
|
|
|
)
|
|
|
+ return sorted((t.tag.to_view() for t in query), key=lambda t: t.name,)
|
|
|
+
|
|
|
|
|
|
class Link(Model):
|
|
|
"""
|