server/users: fix fetching columns
This commit is contained in:
parent
2ac8d8650c
commit
1019062698
2 changed files with 12 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
from sqlalchemy import Column, Integer, DateTime, UnicodeText, ForeignKey
|
from sqlalchemy import Column, Integer, DateTime, UnicodeText, ForeignKey
|
||||||
from sqlalchemy.orm import relationship, object_session
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.sql.expression import func
|
from sqlalchemy.sql.expression import func
|
||||||
from szurubooru.db.base import Base
|
from szurubooru.db.base import Base
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from sqlalchemy import Column, Integer, Unicode, DateTime
|
from sqlalchemy import Column, Integer, Unicode, DateTime
|
||||||
from sqlalchemy.orm import object_session
|
from sqlalchemy.sql.expression import func
|
||||||
from sqlalchemy.sql.expression import func, select
|
|
||||||
from szurubooru.db.base import Base
|
from szurubooru.db.base import Base
|
||||||
from szurubooru.db.post import Post, PostScore, PostFavorite
|
from szurubooru.db.post import Post, PostScore, PostFavorite
|
||||||
from szurubooru.db.comment import Comment
|
from szurubooru.db.comment import Comment
|
||||||
|
@ -32,28 +31,32 @@ class User(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def post_count(self):
|
def post_count(self):
|
||||||
return object_session(self) \
|
from szurubooru.db import session
|
||||||
|
return session \
|
||||||
.query(func.sum(1)) \
|
.query(func.sum(1)) \
|
||||||
.filter(Post.user_id == self.user_id) \
|
.filter(Post.user_id == self.user_id) \
|
||||||
.one()[0] or 0
|
.one()[0] or 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def comment_count(self):
|
def comment_count(self):
|
||||||
return object_session(self) \
|
from szurubooru.db import session
|
||||||
|
return session \
|
||||||
.query(func.sum(1)) \
|
.query(func.sum(1)) \
|
||||||
.filter(Comment.user_id == self.user_id) \
|
.filter(Comment.user_id == self.user_id) \
|
||||||
.one()[0] or 0
|
.one()[0] or 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def favorite_post_count(self):
|
def favorite_post_count(self):
|
||||||
return object_session(self) \
|
from szurubooru.db import session
|
||||||
|
return session \
|
||||||
.query(func.sum(1)) \
|
.query(func.sum(1)) \
|
||||||
.filter(PostFavorite.user_id == self.user_id) \
|
.filter(PostFavorite.user_id == self.user_id) \
|
||||||
.one()[0] or 0
|
.one()[0] or 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def liked_post_count(self):
|
def liked_post_count(self):
|
||||||
return object_session(self) \
|
from szurubooru.db import session
|
||||||
|
return session \
|
||||||
.query(func.sum(1)) \
|
.query(func.sum(1)) \
|
||||||
.filter(PostScore.user_id == self.user_id) \
|
.filter(PostScore.user_id == self.user_id) \
|
||||||
.filter(PostScore.score == 1) \
|
.filter(PostScore.score == 1) \
|
||||||
|
@ -61,7 +64,8 @@ class User(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def disliked_post_count(self):
|
def disliked_post_count(self):
|
||||||
return object_session(self) \
|
from szurubooru.db import session
|
||||||
|
return session \
|
||||||
.query(func.sum(1)) \
|
.query(func.sum(1)) \
|
||||||
.filter(PostScore.user_id == self.user_id) \
|
.filter(PostScore.user_id == self.user_id) \
|
||||||
.filter(PostScore.score == -1) \
|
.filter(PostScore.score == -1) \
|
||||||
|
|
Loading…
Reference in a new issue