From 79c76b1337003ea3518a8c8b81653943957ff505 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Fri, 10 Apr 2026 07:43:09 +0200 Subject: [PATCH] fix: views_count increment no longer triggers updated_at on classifieds Use raw SQL UPDATE for views_count to bypass SQLAlchemy onupdate. Restore updated_at display in homepage cards - now accurate. Co-Authored-By: Claude Opus 4.6 (1M context) --- blueprints/community/classifieds/routes.py | 8 ++++++-- templates/index.html | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/blueprints/community/classifieds/routes.py b/blueprints/community/classifieds/routes.py index 97eb933..1a37d55 100644 --- a/blueprints/community/classifieds/routes.py +++ b/blueprints/community/classifieds/routes.py @@ -166,8 +166,12 @@ def view(classified_id): flash('Ogłoszenie nie istnieje.', 'error') return redirect(url_for('.classifieds_index')) - # Zwiększ licznik wyświetleń (handle NULL) - classified.views_count = (classified.views_count or 0) + 1 + # Zwiększ licznik wyświetleń bez triggerowania updated_at + db.execute( + Classified.__table__.update().where(Classified.id == classified_id).values( + views_count=(Classified.views_count + 1) + ) + ) # Zapisz odczyt przez zalogowanego użytkownika existing_read = db.query(ClassifiedRead).filter( diff --git a/templates/index.html b/templates/index.html index 0d40a86..1cebc75 100755 --- a/templates/index.html +++ b/templates/index.html @@ -1302,7 +1302,7 @@ 🏢 B2B {% if cl.listing_type == 'szukam' %}Szukam{% else %}Oferuję{% endif %}
{{ cl.title }}
- {{ cl.author.name if cl.author else 'Anonim' }} · {{ cl.created_at|local_time('%d.%m.%Y') }} + {{ cl.author.name if cl.author else 'Anonim' }} · {{ (cl.updated_at or cl.created_at)|local_time('%d.%m.%Y') }}
{% endfor %}