Hi,

I think "choices" in Appengine models does not work in the same way as
in Django models and does not expect a list of tuples in the form
(label, value) but a simple list of values.

See
http://code.google.com/intl/pt-PT/appengine/docs/python/datastore/propertyclass.html#Property
https://code.google.com/intl/pt-PT/appengine/docs/python/datastore/overview.html#Data_Modeling_With_Python
http://code.google.com/p/googleappengine/issues/detail?id=350


Also you for loop seems suspicious:
{% for sexo in sexo_listar value %}

I've don't think this extra "value" word is valid nor mentioned in the docs:
http://www.djangoproject.com/documentation/0.96/templates/#for

hth,
Nuno


On Mon, Aug 9, 2010 at 9:46 PM, Ipca - Instituto Politécnico Cávado e
Ave IPCA <ipca...@gmail.com> wrote:
> Hi,
> Need help to implement a form that displays the template´s choices
> from my models.py file.
> When i try to access the handler guardaPerfil, it shows the forms but
> doesn´t fill neither is accesible to select choices created.
>
>
> -----------------Here´s my models.py: ----------------------
> from google.appengine.ext import db
> from google.appengine.ext.db import djangoforms
> from google.appengine.api import users
> from django import newforms
>
> ESCOLHA_SEXO = (
>                ('M', 'masculino'),
>                ('F', 'feminino'),
>                )
> ESCOLA =(
>        ('EST', 'Escola Superior Tecnologia'),
>        ('ESG', 'Escola Superior de Gestao'),
>        )
>
> class Conta(db.Model):
>    user=db.UserProperty(u'user', required=True)
>    nome=db.StringProperty(u'nome', required=True)
>    apelido=db.StringProperty(u'apelido', required=True)
>    sexo=db.StringProperty(u'Sexo', required=False, choices =
> ESCOLHA_SEXO)
>    email=db.EmailProperty(u'email', required=True)
>    escola=db.StringProperty(u'escola', required=False, choices =
> ESCOLA)
>
> class Utilizador(db.Model):
>    user=db.UserProperty(u'user', required=False)
>    foto = db.BlobProperty(u'foto')
>
>
> ------------------------------Here´s my
> forms.py:---------------------------------
> from google.appengine.ext.webapp import template
> from google.appengine.ext.db import djangoforms
> import models
>
> class ContaForm(djangoforms.ModelForm):
>    class Meta:
>        model=models.Conta
>        exclude = ['user']
>
> class UtilizadorForm(djangoforms.ModelForm):
>    class Meta:
>        model=models.Utilizador
>        exclude = ['user']
>
> ----------------------------Here´s my
> Handler:---------------------------
> class GuardarPerfilHandler(webapp.RequestHandler):
>    def post(self):
>        if self.request.get('escolhe_conta'):
>            id = int(self.request.get('escolhe_conta'))
>            conta = models.Conta.get(db.Key.from_path('Conta', id))
>        else:
>            conta = models.Conta()
>
>        data = forms.ContaForm(data = self.request.POST)
>        if data.is_valid():
>            if users.get_current_user():
>                conta.user = users.get_current_user()
>
>            conta.nome = self.request.get('nome')
>            conta.apelido = self.request.get('apelido')
>            conta.sexo = self.request.get('sexo')
>            conta.email = self.request.get('email')
>            conta.escola = self.request.get('escola')
>
>            conta.put()
>            self.redirect('/perfil')
>        else:
>            path = os.path.join(os.path.dirname(__file__), 'templates/
> guardaPerfil.html')
>            self.response.out.write(template.render(path, locals(),
> debug = True))
>
>    def get(self):
>        user=users.get_current_user()
>        if user:
>            greeting=("<ul><li><strong><b>%s </b></strong>|</li><li><a
> href=\"/perfil\"> Minha Conta </a>|</li><li><a href=\"%s\">Logout</a></
> li></ul>" %(user.nickname(), users.create_logout_url("/")))
>        else:
>            greeting = ("<ul><li><a href=\"%s\">Login</a></li></ul>" %
> (users.create_login_url("/")))
>
>        contaForm = ("<form method=\"POST\" action=\"\"><table>%s</
> table><input type=\"submit\" value=\"kkkkk\" /></form>" %
> (forms.ContaForm()))
>
>        conta = db.Query(models.Conta)
>        conta = conta.filter('user =', user)
>        conta_lista = conta.fetch(limit = 1)
>
>        escola_list = models.Conta.escola.choices
>        sexo_listar = models.Conta.sexo.choices
>
>        path = os.path.join(os.path.dirname(__file__), 'templates/
> guardaPerfil.html')
>        self.response.out.write(template.render(path, locals(),
> debug=True))
>
> -------------------------Here´s my
> tenplate--------------------------------
>
> <td>Sexo: </td>
>                                                <td>
>                                                        {% for sexo in 
> sexo_listar value %}
>                                                                {% ifequal 
> escolhe_conta.sexo.sexo sexo.sexo %}
>                                                                        
> <label><input type="radio" name="escolhe_sexo"
> value="{{ sexo.sexo }}" checked />{{ sexo.sexo }}</label>
>                                                                {% else %}
>                                                                        
> <label><input type="radio" name="escolhe_sexo"
> value="{{ sexo.sexo }}" />{{ sexo.sexo }}</label>
>                                                                {% endifequal 
> %}
>                                                        {% endfor %}
>                                                </td>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine" group.
> To post to this group, send email to google-appeng...@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to