def add_task(): desc = request.POST.description.strip() if len(desc) > 0: t = TodoItem(desc) s.add(t) s.commit() return redirect("/")
def add_task(): desc = request.POST.description.strip() auth = request.POST.author today = dt.now().date() if len(desc) > 0 and len(auth) > 0: t = TodoItem(desc, auth, today) s.add(t) s.commit() return redirect("/")
def add_task(): incomplete = s.query(TodoItem).filter(TodoItem.is_completed == False).count() print(incomplete) if incomplete >= 10: return redirect('/') desc = request.POST.description.strip() if len(desc) > 0: t = TodoItem(desc) s.add(t) s.commit() return redirect("/")
def add_task(): desc = request.POST.description.strip( ) # поле POST-запроса description совпадает с именем # формы из страницы HTML (<input class='form-control' name='description'>) incomplete_tasks = s.query(TodoItem).filter( TodoItem.is_completed == False).count() if len(desc) > 0 and incomplete_tasks < 10: t = TodoItem(desc) s.add(t) s.commit() else: redirect('/error') return redirect('/')
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from db import Base, TodoItem engine = create_engine("sqlite:///tasks.db", echo=True) Base.metadata.create_all(engine) Sesion = sessionmaker(bind=engine) s = Sesion() for desc in ("read book", "learn python", "wash footwear", "eat"): t = TodoItem(desc) s.add(t) s.commit()
# Init database from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from db import Base, TodoItem engine = create_engine("sqlite:///tasks.db", echo=True) Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) s = Session() for desc in ("Eat", "Sleep", "Python", "Hello world!"): auth = "Savva" dt = "2020-03-20" t = TodoItem(desc, auth, dt) s.add(t) s.commit()