Forms 谷歌AppEngine:表单处理&x27;重复';结构属性

Forms 谷歌AppEngine:表单处理&x27;重复';结构属性,forms,google-app-engine,app-engine-ndb,Forms,Google App Engine,App Engine Ndb,在设计ndb.StructuredProperty(repeated=True)属性的窗体和处理程序时,如何使用它们?考虑这个例子: 我有三种类型的ndb。模型:有技能的人,他的教育,和他的(工作)经验。后两种是技术人员的结构属性类型 class SkilledPerson(ndb.Model): name = ndb.StringProperty() birth = ndb.DateProperty() education = ndb.StructuredPropert

在设计ndb.StructuredProperty(repeated=True)属性的窗体和处理程序时,如何使用它们?考虑这个例子:

我有三种类型的ndb。模型:有技能的人,他的教育,和他的(工作)经验。后两种是技术人员的结构属性类型

class SkilledPerson(ndb.Model):
    name = ndb.StringProperty()
    birth = ndb.DateProperty()
    education = ndb.StructuredProperty(Education, repeated = True)
    experience = ndb.StructuredProperty(Experience, repeated = True)

class Education(ndb.Model):
    institution = ndb.StringProperty()
    certification = ndb.StringProperty()
    start = ndb.DateProperty()
    finish = ndb.DateProperty()

class Experience(ndb.Model):
    job_title = ndb.StringProperty()
    workplace = ndb.StringProperty()
    start = ndb.DateProperty()
    finish = ndb.DateProperty()
我将如何为熟练人员实体创建表单?它将显示简单的字段,如名称和出生(StringProperty和DateProperty)。此外,它必须显示教育和体验结构属性的“组”字段。我会想象这个表格是这样的:

<form method="post">

<h2>Skilled Person Form</h2>

    <label>Name<br> 
        <input type="text" name="name" value="{{name}}">
    </label>


    <label>Birth<br> 
        <input type="date" name="birth" value="{{birth}}">
    </label>


    <!-- Education form goes here -->

    <!-- and Experience form goes here -->

    <input type="submit">

</form>

技术人员表格
名称
出生
我如何在此表格中包括教育和经验领域组

教育表格示例:


增加教育
机构
认证
开始
完成

使用Jinja2,您可以创建一个循环,为每次教育和每次体验生成HTML

您可以使用特殊的Jinja变量loop.index分配唯一的名称,如education-1…education-4:
“name-{{loop.index}}”

如果需要大量的表单处理和验证,可以使用WTForms。 见文件:

如果需要更改表单中的教育和经历列表,则必须使用javascript和jquery添加新项(表单字段)或删除项(表单字段)

<form method="post">

<h2>Add Education</h2>

    <label>Institution<br> 
        <input type="text" name="institution" value="{{institution}}">
    </label>

    <label>Certification<br> 
        <input type="text" name="certification" value="{{certification}}">
    </label>

    <label>Start<br> 
        <input type="date" name="start" value="{{start}}">
    </label>

    <label>Finish<br> 
        <input type="date" name="finish" value="{{finish}}">
    </label>

    <input type="submit">

</form>