Schematics python multiple object in list

952 Views Asked by At

I have defined models in schematics like this:

class A(Model):
   value: StringType = StringType(required=True)

class B(Model):
   type: StringType = StringType(required=True)

and I want to have this two model types defined in one List something like this:

class C(Model):
   list_of_values: ListType = ListType(ModelType(A), ModelType(B), required=True)

Can someone help me how to do that ?

1

There are 1 best solutions below

0
Hitobat On

I think you need to use PolyModelType for this. Something like the following (untested) code:

class C(Model):
    list_of_values = ListType(PolyModelType([A, B]), required=True)