Python 3.x Python示意图忽略rogue字段名,但验证其值

Python 3.x Python示意图忽略rogue字段名,但验证其值,python-3.x,orm,python-schematics,Python 3.x,Orm,Python Schematics,假设我有以下JSON: { "name": "Rob", "Occupation": { "Painter": [ { "company" : "X", "years" : "1980-1997" }, { "company" : "Y", "yea

假设我有以下JSON:

{
   "name": "Rob",
   "Occupation": {
        "Painter": [
             { 
                "company" : "X",
                 "years" : "1980-1997"    
             },
             {
                 "company" : "Y",
                 "years" : "1999-2000"   
             }
         ],
         "Singer": [
             {
                 "company" : "A",
                 "years" : "2001-2005"   
             }
         ]
   }
}
“画家”和“歌手”的“职业”领域显然可以转变为其他领域。如何使用
schematics

到目前为止,我有以下资料:

from schematics import models, types

class Person(models.Model):
    name = types.StringType()
    occupation = types.ModelType(OccupationModel, serialized_name="Occupation")

class Occupation(models.Model):
    ## Here is where I don't know what to do!!! 

因此,经过大量的修补,终于找到了一种方法来做到这一点。有趣的是,在schematics模块的test case文件夹中找到了一个示例:

下面是我最后做的:

class OccupationModel(models.Model):
    company = types.StringType()
    years = types.StringType()

class Person(models.Model):
    name = types.StringType()
    occupation = types.DictType(types.ListType(types.ModelType(OccupationModel)), serialized_name="Occupation")