From 46e61c0f26a55da48e6515e4dd1c1c67b8e28e8a Mon Sep 17 00:00:00 2001 From: thomaswoehlke <thomas.woehlke@gmail.com> Date: Sun, 25 Apr 2021 17:27:34 +0200 Subject: [PATCH] work --- src/covid19/blueprints/who/who_model.py | 24 +++++++++++-------- .../blueprints/who_test/who_test_views.py | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/covid19/blueprints/who/who_model.py b/src/covid19/blueprints/who/who_model.py index 298b7cae..7a52374f 100644 --- a/src/covid19/blueprints/who/who_model.py +++ b/src/covid19/blueprints/who/who_model.py @@ -1,7 +1,8 @@ from sqlalchemy import and_, func from datetime import date from database import db, ITEMS_PER_PAGE -from sqlalchemy.orm import joinedload, load_only +from sqlalchemy.orm import joinedload, load_only, defaultload, defer, undefer, query_expression, subqueryload +from sqlalchemy.sql import select from covid19.blueprints.application.application_model import ApplicationDateReported, ApplicationRegion @@ -59,7 +60,6 @@ class WhoDateReported(ApplicationDateReported): year_week=my_year_week ) - class WhoRegion(ApplicationRegion): __tablename__ = 'who_country_region' __mapper_args__ = {'concrete': True} @@ -199,14 +199,6 @@ class WhoData(db.Model): cascade='save-update', order_by='asc(WhoCountry.country)') - @classmethod - def get_datum_of_all_who_data(cls): - return db.session.query(WhoData)\ - .join(WhoDateReported, WhoData.date_reported)\ - .options(load_only(WhoDateReported.date_reported))\ - .group_by(WhoDateReported.date_reported)\ - .all() - @classmethod def remove_all(cls): for one in cls.get_all(): @@ -366,3 +358,15 @@ class WhoData(db.Model): ).order_by( cls.deaths_cumulative.desc() ).paginate(page, per_page=ITEMS_PER_PAGE) + + @classmethod + def get_datum_of_all_who_data(cls): + return db.session.query(cls).options(subqueryload("date_reported").load_only("date_reported_import_str")) + + @classmethod + def get_datum_of_all_who_data2(cls): + stmt = ( + select(WhoData,WhoDateReported).join(WhoData.date_reported).filter(WhoData.date_reported_id == WhoDateReported.id)\ + .options(defaultload("someattr").defer("some_column")) + ) + return db.session.query() \ No newline at end of file diff --git a/src/covid19/blueprints/who_test/who_test_views.py b/src/covid19/blueprints/who_test/who_test_views.py index abcc2089..38fe69d3 100644 --- a/src/covid19/blueprints/who_test/who_test_views.py +++ b/src/covid19/blueprints/who_test/who_test_views.py @@ -87,7 +87,7 @@ def url_who_test_who_data_get_datum_of_all_who_data(): app.logger.info("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") flash("url_who_test_who_data_get_datum_of_all_who_data - START: WhoData.get_datum_of_all_who_data()") for datum in WhoData.get_datum_of_all_who_data(): - app.logger.info(str(datum.date_reported)) + app.logger.info(str(datum)) flash("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") app.logger.info("url_who_test_who_data_get_datum_of_all_who_data - DONE: WhoData.get_datum_of_all_who_data()") return redirect(url_for('who_test.url_who_test_tests')) -- GitLab