How to programmatically determine if a ndb property is multivalued

I translated the application from Datastore to ndb and ran into a problem in the xml import procedure. The problem is that I cannot programmatically determine if a property of the ndb.model class is a multi-valued property or not.

I suspect this is due to a lack of basic Python skills, as the code I have cited so far shows that the value is "visible." Therefore, I cannot grab him. Please, help.

from google.appengine.ext import ndb

class House(ndb.Model):
  name = ndb.StringProperty()   
  rooms = ndb.StringProperty(repeated=True) 

print 'Properties:'
for p in House._properties:
  print getattr(House,p)

print '\nRepeated:'
for p in House._properties:
  print getattr(getattr(House,p),'repeated',None)

The result is the following:

Properties:
StringProperty('rooms', repeated=True)
StringProperty('name')

Repeated:
None
None
+3
source share
2 answers

, - API. , , . : http://code.google.com/p/appengine-ndb-experiment/issues/detail?id=187

, , House._properties, , . (, __dict__ NDB.)

+8

NDB - ; . , - . , , .

, :

properties = [(k, v) for k, v in House.__dict__.items() if isinstance(v, ndb.Property)]

, , _repeated , - . , , , :

House.rooms._repeated

getattr(House, 'rooms')._repeated
+5

All Articles