Add a 'due' field to tasks
This commit is contained in:
parent
31b5832fe1
commit
c17a67df72
32
alembic/versions/17946e7038d7_add_due_date_to_tasks.py
Normal file
32
alembic/versions/17946e7038d7_add_due_date_to_tasks.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"""add due date to tasks
|
||||||
|
|
||||||
|
Revision ID: 17946e7038d7
|
||||||
|
Revises: 719f2d1539c8
|
||||||
|
Create Date: 2020-05-21 10:49:26.110397
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '17946e7038d7'
|
||||||
|
down_revision = '719f2d1539c8'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column(
|
||||||
|
'tasks',
|
||||||
|
sa.Column(
|
||||||
|
'due_at',
|
||||||
|
sa.DateTime,
|
||||||
|
nullable=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
with op.batch_alter_table('tasks') as tasks:
|
||||||
|
tasks.drop_column('due_at')
|
@ -1,2 +1,3 @@
|
|||||||
alembic
|
alembic
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
|
dateparser
|
||||||
|
@ -3,14 +3,19 @@
|
|||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
import sqlalchemy.ext.automap
|
import sqlalchemy.ext.automap
|
||||||
|
|
||||||
|
import dateparser
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
Base = sa.ext.automap.automap_base()
|
Base = sa.ext.automap.automap_base()
|
||||||
Task = None
|
Task = None
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
def add(session: sa.orm.Session, title: str):
|
def add(session: sa.orm.Session, title: str, due: str = None):
|
||||||
obj = Task(title=title)
|
if due is not None:
|
||||||
|
due = dateparser.parse(due)
|
||||||
|
|
||||||
|
obj = Task(title=title, due_at=due)
|
||||||
session.add(obj)
|
session.add(obj)
|
||||||
session.commit()
|
session.commit()
|
||||||
show_by_obj(session, obj)
|
show_by_obj(session, obj)
|
||||||
@ -32,7 +37,7 @@ def rm(session: sa.orm.Session, index: int):
|
|||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def show_by_obj(session: sa.orm.Session, obj: Task):
|
def show_by_obj(session: sa.orm.Session, obj: Task):
|
||||||
print(obj.id, obj.created_at, obj.active, obj.title)
|
print(obj.id, obj.created_at, obj.due_at, obj.active, obj.title)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@ -76,8 +81,9 @@ if __name__ == '__main__':
|
|||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
|
|
||||||
add_parser = subparsers.add_parser('add')
|
add_parser = subparsers.add_parser('add')
|
||||||
add_parser.set_defaults(func=add)
|
add_parser.set_defaults(func=add, due=None)
|
||||||
add_parser.add_argument("title", type=str)
|
add_parser.add_argument("title", type=str)
|
||||||
|
add_parser.add_argument("--due", type=str)
|
||||||
|
|
||||||
done_parser = subparsers.add_parser('done')
|
done_parser = subparsers.add_parser('done')
|
||||||
done_parser.set_defaults(func=done)
|
done_parser.set_defaults(func=done)
|
||||||
|
Loading…
Reference in New Issue
Block a user