Sort notifications in reverse order

This commit is contained in:
rubenwardy 2020-12-05 22:36:00 +00:00
parent 64a180ba8f
commit b3bd7ac615
2 changed files with 8 additions and 1 deletions

@ -23,6 +23,7 @@ from flask import url_for
from flask_login import UserMixin from flask_login import UserMixin
from flask_migrate import Migrate from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy, BaseQuery from flask_sqlalchemy import SQLAlchemy, BaseQuery
from sqlalchemy import desc, text
from sqlalchemy_searchable import SearchQueryMixin, make_searchable from sqlalchemy_searchable import SearchQueryMixin, make_searchable
from sqlalchemy_utils.types import TSVectorType from sqlalchemy_utils.types import TSVectorType
@ -166,7 +167,7 @@ class User(db.Model, UserMixin):
# Content # Content
notifications = db.relationship("Notification", primaryjoin="User.id==Notification.user_id", notifications = db.relationship("Notification", primaryjoin="User.id==Notification.user_id",
order_by="Notification.created_at") order_by=desc(text("Notification.created_at")))
notification_preferences = db.relationship("UserNotificationPreferences", uselist=False, back_populates="user") notification_preferences = db.relationship("UserNotificationPreferences", uselist=False, back_populates="user")

@ -14,6 +14,12 @@ Notifications
<h1>Notifications</h1> <h1>Notifications</h1>
{% if current_user.notifications %}
<p>
Newest first.
</p>
{% endif %}
<div class="list-group mt-3"> <div class="list-group mt-3">
{% for n in current_user.notifications %} {% for n in current_user.notifications %}
<a class="list-group-item list-group-item-action" href="{{ n.url }}"> <a class="list-group-item list-group-item-action" href="{{ n.url }}">