Имею модель описаную с помощью sqlalchemy_defaults. При попытке валидации формы валится и кричит:
Error in the Дата field - Not a valid date value
Где прописать формат даты?
планируется вводить в формате ‘%d.%m.%Y’
Error in the Дата field - Not a valid date value
from app import db from sqlalchemy import Integer, String, Text, Float, Date from sqlalchemy_defaults import make_lazy_configured, Column make_lazy_configured(db.mapper) # Мероприятие class Olympiad(db.Model): __tablename__ = 'Olympiad' id = Column(Integer, primary_key=True, nullable=False, autoincrement=True) name = Column(String, label='Название', nullable=False) date = Column(Date, label='Дата', nullable=False) description = Column(String, label='Описание') def __init__(self, name, date, description=None): self.name = name self.date = date self.description = description
from app.models import Olympiad from flask.ext.wtf import Form from wtforms_alchemy import model_form_factory ModelForm = model_form_factory(Form) class OlympiadForm(ModelForm, Form): class Meta: model = Olympiad
@app.route('/olympiads/', methods=['POST', 'GET']) def olympiads(): instances = list() olympiads = db.session.query(Olympiad).limit(OBJECT_PER_PAGE) for olympiad in olympiads: instances.append((olympiad, OlympiadForm())) editor = OlympiadForm() if request.method == 'POST' and editor.validate(): olympiad = Olympiad(name=editor.name.data, date=editor.date.data, description=editor.description.data) db.session.add(olympiad) db.session.commit() flash('Олимпиада добавлена! \n %s: %s' % (olympiad.id, olympiad.name), 'info') flash_errors(editor) return render_template('olympiad.html', breadcrumbs=breadcrumbs[:2], olympiads=instances, form=editor)
if request.method == 'POST' and editor.validate():
if form.validate_on_submit():
obj = MyModel.query.get(1) form = MyForm(obj=obj) form.populate_obj(obj) form.validate()