From b3bd7ac615d2a4cfedc2ac624b362c24f6999910 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 5 Dec 2020 22:36:00 +0000 Subject: [PATCH] Sort notifications in reverse order --- app/models.py | 3 ++- app/templates/notifications/list.html | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 7673d4ef..8893853e 100644 --- a/app/models.py +++ b/app/models.py @@ -23,6 +23,7 @@ from flask import url_for from flask_login import UserMixin from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy, BaseQuery +from sqlalchemy import desc, text from sqlalchemy_searchable import SearchQueryMixin, make_searchable from sqlalchemy_utils.types import TSVectorType @@ -166,7 +167,7 @@ class User(db.Model, UserMixin): # Content 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") diff --git a/app/templates/notifications/list.html b/app/templates/notifications/list.html index 6d307951..85178742 100644 --- a/app/templates/notifications/list.html +++ b/app/templates/notifications/list.html @@ -14,6 +14,12 @@ Notifications

Notifications

+ {% if current_user.notifications %} +

+ Newest first. +

+ {% endif %} +
{% for n in current_user.notifications %}