Skip to content
Snippets Groups Projects
Commit 17a0bb11 authored by thomaswoehlke's avatar thomaswoehlke
Browse files

work

parent a7a75153
No related branches found
No related tags found
2 merge requests!161Issue 66 attempt 01,!160Issue 66 attempt 01
......@@ -71,8 +71,8 @@ class CommonDateReported(db.Model):
@classmethod
def remove_all(cls):
# TODO: SQLalchemy instead of SQL
db.session.execute("delete from " + cls.__tablename__)
for one in cls.get_all():
db.session.delete(one)
db.session.commit()
return None
......@@ -123,13 +123,16 @@ class CommonRegion(db.Model):
'polymorphic_identity': 'common_date_reported',
'polymorphic_on': type
}
__table_args__ = (
db.UniqueConstraint('type', 'region', name='unique_common_region_reported'),
)
id = db.Column(db.Integer, primary_key=True)
region = db.Column(db.String(255), unique=True)
@classmethod
def remove_all(cls):
# TODO: SQLalchemy instead of SQL
db.session.execute("delete from " + cls.__tablename__)
for one in cls.get_all():
db.session.delete(one)
db.session.commit()
return None
......
......@@ -47,8 +47,8 @@ class EuropeCountry(db.Model):
@classmethod
def remove_all(cls):
# TODO: SQLalchemy instead of SQL
db.session.execute("delete from " + cls.__tablename__ + " cascade")
for one in cls.get_all():
db.session.delete(one)
db.session.commit()
return None
......@@ -101,8 +101,8 @@ class EuropeData(db.Model):
@classmethod
def remove_all(cls):
# TODO: SQLalchemy instead of SQL
db.session.execute("delete from " + cls.__tablename__ + " cascade")
for one in cls.get_all():
db.session.delete(one)
db.session.commit()
return None
......
......@@ -18,19 +18,25 @@ class EuropeDataImportTable(db.Model):
@classmethod
def remove_all(cls):
# TODO: SQLalchemy instead of SQL
db.session.execute("delete from " + cls.__tablename__ + " cascade")
for one in cls.get_all():
db.session.delete(one)
db.session.commit()
return None
@classmethod
def get_all_as_page(cls, page):
#TODO: #51 order_by: year_week, country
return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE)
return db.session.query(cls).order_by(
cls.year_week,
cls.countries_and_territories
).paginate(page, per_page=ITEMS_PER_PAGE)
@classmethod
def get_all(cls):
return db.session.query(cls).all()
return db.session.query(cls).order_by(
cls.year_week,
cls.countries_and_territories
).all()
@classmethod
def get_by_id(cls, other_id):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment