class - Python: Loop over NDB entity model -
i have class/ndb entity model defined follows:
class cashmodel(ndb.model): "models cash record" # name, balance, interest rate accountname = ndb.stringproperty() interestrate = ndb.floatproperty() balance = ndb.floatproperty() accounttype = ndb.stringproperty() futureview = ndb.jsonproperty() time_stored = ndb.datetimeproperty(auto_now_add=true)
once values added class
, print out of looks this:
cashmodel(accountname=u'bank', accounttype=u'cash', balance=1000.0, futureview=none, interestrate=5.0, time_stored=datetime.datetime(2015, 7, 7, 18, 33, 3, 925601))
how loop on key/value pairs of class, output like:
accountname, bank accounttype, cash balance, 1000.0 futureview, none interestrate, 5.0 time_stored, datetime.datetime(2015, 7, 7, 18, 33, 3, 925601)
looked through other answer on s.o., none seemed fit. simple solution using built-in method best. tia
you can use to_dict(include=none, exclude=none)
instance method convert model object dictionary , use iteritems()
iterate on key/value pairs
to_dict(include=none, exclude=none)
returns dict containing model's property values.
Comments
Post a Comment