From 1019062698e60340a7626d44388712aac29de8a0 Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 16 Jun 2016 20:03:40 +0200 Subject: [PATCH] server/users: fix fetching columns --- server/szurubooru/db/comment.py | 2 +- server/szurubooru/db/user.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/server/szurubooru/db/comment.py b/server/szurubooru/db/comment.py index 94f01257..cfe6c90b 100644 --- a/server/szurubooru/db/comment.py +++ b/server/szurubooru/db/comment.py @@ -1,5 +1,5 @@ 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 szurubooru.db.base import Base diff --git a/server/szurubooru/db/user.py b/server/szurubooru/db/user.py index da5f48d0..705f0fd6 100644 --- a/server/szurubooru/db/user.py +++ b/server/szurubooru/db/user.py @@ -1,6 +1,5 @@ from sqlalchemy import Column, Integer, Unicode, DateTime -from sqlalchemy.orm import object_session -from sqlalchemy.sql.expression import func, select +from sqlalchemy.sql.expression import func from szurubooru.db.base import Base from szurubooru.db.post import Post, PostScore, PostFavorite from szurubooru.db.comment import Comment @@ -32,28 +31,32 @@ class User(Base): @property def post_count(self): - return object_session(self) \ + from szurubooru.db import session + return session \ .query(func.sum(1)) \ .filter(Post.user_id == self.user_id) \ .one()[0] or 0 @property def comment_count(self): - return object_session(self) \ + from szurubooru.db import session + return session \ .query(func.sum(1)) \ .filter(Comment.user_id == self.user_id) \ .one()[0] or 0 @property def favorite_post_count(self): - return object_session(self) \ + from szurubooru.db import session + return session \ .query(func.sum(1)) \ .filter(PostFavorite.user_id == self.user_id) \ .one()[0] or 0 @property def liked_post_count(self): - return object_session(self) \ + from szurubooru.db import session + return session \ .query(func.sum(1)) \ .filter(PostScore.user_id == self.user_id) \ .filter(PostScore.score == 1) \ @@ -61,7 +64,8 @@ class User(Base): @property def disliked_post_count(self): - return object_session(self) \ + from szurubooru.db import session + return session \ .query(func.sum(1)) \ .filter(PostScore.user_id == self.user_id) \ .filter(PostScore.score == -1) \