poprawka zapytania
This commit is contained in:
29
app.py
29
app.py
@@ -1162,17 +1162,30 @@ def get_active_months_query(visible_lists_query=None):
|
||||
month_col = func.strftime("%Y-%m", ShoppingList.created_at)
|
||||
elif db.engine.name in ("mysql", "mariadb"):
|
||||
month_col = func.date_format(ShoppingList.created_at, "%Y-%m")
|
||||
else: # PostgreSQL i inne wspierające to_char
|
||||
else: #PGSQL
|
||||
month_col = func.to_char(ShoppingList.created_at, "YYYY-MM")
|
||||
|
||||
query = db.session.query(month_col.label("month"))
|
||||
if visible_lists_query is not None:
|
||||
query = query.select_from(visible_lists_query.subquery())
|
||||
month_col = month_col.label("month")
|
||||
|
||||
active_months = (
|
||||
query.filter(ShoppingList.created_at != None).distinct().order_by("month").all()
|
||||
)
|
||||
return [row.month for row in active_months]
|
||||
if visible_lists_query is not None:
|
||||
inner = (
|
||||
db.session.query(month_col)
|
||||
.select_from(visible_lists_query.subquery())
|
||||
.filter(month_col.isnot(None))
|
||||
.distinct()
|
||||
.subquery()
|
||||
)
|
||||
else:
|
||||
inner = (
|
||||
db.session.query(month_col)
|
||||
.select_from(ShoppingList)
|
||||
.filter(ShoppingList.created_at.isnot(None))
|
||||
.distinct()
|
||||
.subquery()
|
||||
)
|
||||
|
||||
rows = db.session.query(inner.c.month).order_by(inner.c.month).all()
|
||||
return [r.month for r in rows]
|
||||
|
||||
|
||||
def normalize_name(name):
|
||||
|
Reference in New Issue
Block a user