Created
November 13, 2010 00:09
-
-
Save fsouza/674935 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, render_template | |
from flaskext import wtf | |
from wtforms.ext.appengine.db import model_form | |
from google.appengine.ext import db | |
app = Flask(__name__) | |
class Pessoa(db.Model): | |
nome = db.StringProperty(required=True) | |
class Carro(db.Model): | |
fabricante = db.StringProperty(required=True) | |
nome = db.StringProperty(required=True) | |
dono = db.ReferenceProperty(Pessoa, required=True) | |
FormPessoa = model_form(Pessoa, base_class=wtf.Form) | |
FormCarro = model_form(Carro, base_class=wtf.Form) | |
@app.route('/carros/novo', methods=['GET', 'POST']) | |
def novo_carro(): | |
form = FormCarro() | |
if request.method == 'POST' and form.validate_on_submit(): | |
dono = Pessoa.get(form.dono.data) | |
carro = Carro( | |
fabricante=form.fabricante.data, | |
nome=form.nome.data, | |
dono=dono) | |
carro.put() | |
return 'Salvou!' | |
return render_template('novo_carro.html', form=form) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment