Python Appengine表单选项从db.Model中选择

Python Appengine表单选项从db.Model中选择,python,google-app-engine,django-templates,Python,Google App Engine,Django Templates,我的应用程序不会写入数据库中的所有数据。在下面的示例中,只需键入DB名称。“选择”下拉列表中的所有字段都不会记录在数据库中。请帮忙 <tr> <td>Unidade: </td> <td> <select name="docente_unidade"> {% for docente_unidade in conjUnidade %} <option selected> {{ do

我的应用程序不会写入数据库中的所有数据。在下面的示例中,只需键入DB名称。“选择”下拉列表中的所有字段都不会记录在数据库中。请帮忙

<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />
我有一个模型文档

ESCOLHA_SEXO = (u'masculino', u'feminino')
CHOICES_UNIDADE = ('Escola Superior de Tecnologia', 'Escola Superior de Gestao') 
CHOICES_CATEGORIA = ('assistente', 'coordenador', 'adjunto')
CHOICES_REGIME = ('trinta', 'cinquenta', 'sessenta', 'cem')

class Docente(db.Model):
    photo=db.BlobProperty(u'photo')
    docente_nome = db.StringProperty(u'docente_nome', 
                                     required=False)
    docente_unidade = db.StringProperty(u'docente_unidade', 
                                        required=False, 
                                        default='Escola Superior de Tecnologia', 
                                        choices = CHOICES_UNIDADE )
    docente_categoria = db.StringProperty(u'docente_categoria', 
                                          default='assistente', 
                                          choices =CHOICES_CATEGORIA)
    docente_regime = db.StringProperty(u'docente_regime', 
                                       required=False, 
                                       choices =CHOICES_REGIME)
    utilizador=db.ReferenceProperty(Utilizador, 
                                    verbose_name=u'utilizador', 
                                    required=False, 
                                    collection_name='utilizadores')
<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />
这是我的主要观点:

class CriarCvHandler(webapp.RequestHandler):
    def post(self):
        if self.request.get('EscDocente'):
            id = int(self.request.get('EscDocente'))
            docente=models.Docente.get(db.Key.from_path('Docente', id))
        else:
            docente = models.Docente()

        data=forms.DocenteForm(data = self.request.POST)
        if data.is_valid():
            if self.request.get('photo'):
                docente.docente_nome=self.request.get('docente_nome')
                docente.docente_unidade=self.request.get('docente_unidade')
                docente.docente_categoria=self.request.get('docente_categoria')
                docente.docente_regime=self.request.get('docente_regime')

            listaUtlz = models.Utilizador.all()
            listaUtlz.filter('user =', users.get_current_user())

            for utilizador in listaUtlz:
                docente.utilizador=utilizador.key()

            docente.put()
            self.redirect('/academia')
        else:
            self.redirect('/criarCv')

    def get(self):
        user=users.get_current_user()
        if user:
            greeting= ("<ul><li><strong><b>Benvindo %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("/")))

        conjUnidade=models.Docente.docente_unidade.choices
        conjCategoria=models.Docente.docente_categoria.choices
        conjRegime=models.Docente.docente_regime.choices

        utilizador=db.Query(models.Utilizador)
        utilizador=utilizador.filter('user =', user)
        listaUtlz=utilizador.fetch(limit=1)

        if self.request.GET.has_key('id'):
            id=int(self.request.GET['id'])
            EscDocente=models.Docente.get(db.Key.from_path('Docente', id))

        path = os.path.join(os.path.dirname(__file__), 'templates/criarCv.html')
        self.response.out.write(template.render(path, locals(), debug = True))
<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />
class-CriarCvHandler(webapp.RequestHandler):
def post(自我):
如果self.request.get('EscDocente'):
id=int(self.request.get('EscDocente'))
docente=models.docente.get(db.Key.from_路径('docente',id))
其他:
docente=models.docente()
data=forms.DocenteForm(data=self.request.POST)
如果data.is_有效():
如果self.request.get('photo'):
docente.docente\u nome=self.request.get('docente\u nome'))
docente.docente\u unidade=self.request.get('docente\u unidade'))
docente.docente\u categoria=self.request.get('docente\u categoria'))
docente.docente\u政权=self.request.get('docente\u政权')
listaUtlz=models.Utilizador.all()
listaUtlz.filter('user=',users.get_current_user())
对于listaUtlz中的utilizador:
docente.utilizador=utilizador.key()
docente.put()
self.redirect(“/academy”)
其他:
self.redirect(“/criarCv”)
def get(自我):
user=users.get\u current\u user()
如果用户:
问候语=(“
  • Benvindo%s|
    • ”%(user.昵称(),users.create_logout_url(“/”) 其他: 问候语=(“
      ”%(用户。创建登录地址(“/”) conconnidade=models.Docente.Docente_unidade.choices concategoria=models.Docente.Docente\u categoria.choices congent政权=models.Docente.Docente_政权.choices utilizador=db.Query(models.utilizador) utilizador=utilizador.filter('user=',user) listaUtlz=utilizador.fetch(limit=1) 如果self.request.GET.has_key('id'): id=int(self.request.GET['id']) EscDocente=models.Docente.get(db.Key.from_路径('Docente',id)) path=os.path.join(os.path.dirname(_文件__),'templates/criarCv.html') self.response.out.write(template.render(path,locals(),debug=True))
这是我的模板: Nome Docente:

<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />

Unidade:
{conjUnidade%中docente_unidade的百分比}
{{docente_unidade}}
{%endfor%}
类别:
{categoria%}
{%ifequal EscDocente.docente_categoria docente_categoria%}
{{docente_categoria}}
{%else%}
{{docente_categoria}}
{%endifequal%}
{%endfor%}
政体:
{体制%中的docente_体制为%}
{%ifequal EscDocente.docente_regime docente_regime%}
{{docente_政权}
{%else%}
{{docente_政权}
{%endifequal%}
{%endfor%}

更改这些

<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />
<select name="categoria">
<select name="docente_categoria">

<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />

对此

<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />
<select name="categoria">
<select name="docente_categoria">

<tr>
  <td>Unidade: </td>
  <td>
    <select name="docente_unidade">
      {% for docente_unidade in conjUnidade  %}
        <option selected> {{ docente_unidade }} </option>
      {% endfor %}
    </select>
  </td>
</tr>

<tr>
  <td>Categoria: </td>
  <td>
    <select name="categoria">
      <option></option>
        {% for docente_categoria in conjCategoria  %}
          {% ifequal EscDocente.docente_categoria docente_categoria %}
            <option selected> {{ docente_categoria }} </option>
          {% else %}
            <option> {{ docente_categoria }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>
</tr>

<td>Regime: </td>
  <td>
    <select name="regime">
      <option></option>
        {% for docente_regime in conjRegime  %}
          {% ifequal EscDocente.docente_regime docente_regime %}
            <option selected> {{ docente_regime }} </option>
          {% else %}
            <option> {{ docente_regime }} </option>
          {% endifequal %}
        {% endfor %}
    </select>
  </td>

  <tr>
    <td></td>
    <td>
      <input type="button" value="Guardar" onclick="guardaCv()" />


欢迎来到SO。我想你的一些模板没有包括在内。请以后使用“代码格式”按钮或ctrl-k。非常感谢Bernier。这个小问题已经解决了,但我还有一个问题,我已经发布了。我有5个模型实体,需要在同一页上用不同的类填写表单-写入DB和显示值