StructuredProperty inside another StructuredProperty. How?

I have an Entity that has a variable sum of another Entity in it (so I use Structured Property, repeat = True), but this one property can contain a variable of the same entity type. So my code looks like this:

class Property(ndb.Model):
    name    = ndb.StringProperty()
    cost    = ndb.FloatProperty()
    type    = ndb.StringProperty()

class SpecialProperty(ndb.Model):
    name       = ndb.StringProperty()
    properties = ndb.StructuredProperty(Property, repeated=True)
    type       = ndb.StringProperty() 

class Hotel(ndb.Model):
    specialProperties  = ndb.StructuredProperty(SpecialProperty, repeated=True)

But when I try, this GAE causes an error. "TypeError: this StructuredProperty cannot use repeat = True because its model class (SpecialProperty) contains duplicate properties (directly or indirectly).

So how can I get around this? I really need to have this flexible structure.

Thank you very much in advance.

+3
source share
2 answers

StructuredProperty StructuredProperty StructuredProperty, : , . - LocalStructuredProperty, ( ).

https://developers.google.com/appengine/docs/python/ndb/properties#structured

LocalStructuredProperty , . , .

+7

StructuredProperty StructuredProperty.

(, ..). :

class Property(ndb.Model):
    name    = ndb.StringProperty()
    cost    = ndb.FloatProperty()
    type    = ndb.StringProperty()

class SpecialProperty(ndb.Model):
    hotel      = ndb.KeyProperty(Hotel)
    name       = ndb.StringProperty()
    properties = ndb.StructuredProperty(Property, repeated=True)
    type       = ndb.StringProperty() 

class Hotel(ndb.Model):
    # ... hotel properties

. , SpecialProperty Property.

: , JSONProperty.

+3

All Articles