Example #1
0
def create(model):
    instance = get_model_from_key(model)()
    form_cls = get_form_from_key(model)
    form = form_cls(request.form, obj=instance)
    if form.validate():
        form.populate_obj(instance)
        db.session.add(instance)
        db.session.commit()
        return redirect(url_for('get', model=model))
Example #2
0
def get(model):
    instance = get_model_from_key(model).query.first()
    form_cls = get_form_from_key(model)
    form = form_cls(**{"obj": instance} if instance else {})
    is_exist = bool(instance)
    extra = {
        "form": form,
        "submit_value": "Update" if is_exist else "Create",
        "is_exist": is_exist,
        "model_name": instance.__class__.__name__.lower() if instance else model,
    }

    update_extra(extra)
    return render_template('index.html', **extra)
Example #3
0
def delete(model):
    instance = get_model_from_key(model).query.first()
    db.session.delete(instance)
    db.session.commit()
    return redirect(url_for('get', model=model))