Add like counter to user profile

- Also fixed some issue with get_post_count() method? Weird.
This commit is contained in:
Xevion
2022-03-30 01:41:32 -05:00
parent 11394bfb7e
commit 765e786231
2 changed files with 7 additions and 4 deletions

View File

@@ -53,11 +53,11 @@ class User(UserMixin, db.Model):
def get_post_count(self) -> int:
"""Returns the number of posts this user has made."""
return Post.query.filter_by(user_id=self.id).count()
return Post.query.filter_by(author=self).count()
def get_comment_count(self) -> int:
"""Returns the number of comments this user has made."""
return Comment.query.filter_by(user_id=self.id).count()
return Comment.query.filter_by(author=self).count()
def get_post_likes(self) -> int:
"""Returns the number of likes this user's posts have accumulated."""

View File

@@ -4,7 +4,8 @@
<div class="profile-title">
<span class="profile-username">{{ user.name }}</span>
{% if current_user.is_admin or current_user == user %}
<a href="{{ url_for('main.edit_user', username=current_user.username) }}"><i class="fas fa-pencil-alt fa-sm" style="padding-bottom: 3px; padding-left: 0.5em;"></i></a>
<a href="{{ url_for('main.edit_user', username=current_user.username) }}"><i class="fas fa-pencil-alt fa-sm"
style="padding-bottom: 3px; padding-left: 0.5em;"></i></a>
{% endif %}
{% with seen_text = user.get_last_seen_text() %}
{% if seen_text == 'Online now!' %}
@@ -20,7 +21,9 @@
alt="{{ user.username }}'s Profile Picture">
<div class="profile-details">
<span title="{{ user.time_registered }}">Registered {{ user.get_registration_delta() }} ago</span><br>
{# 0 likes<br>#}
{% with like_count = user.get_post_likes() %}
{{ like_count }} like{{ like_count|pluralize }}<br>
{% endwith %}
{% with post_count = user.get_post_count() %}
{{ post_count }} post{{ post_count|pluralize }}<br>
{% endwith %}