mercredi 9 avril 2014

App Engine Python NDB équivalent à Java @NotPersistent - Stack Overflow


Using JDO in Java and App Engine one can mark an entity as being:


@NotPersistent

and essentially get use of the field during runtime, without the field attempting to be persisted during save operations to the datastore.


Does Python have an equivalent to this? Thanks!




in ndb.Model classes you can use a var starting with a underscore to mark a class variable as non-persistant.


    class Person(ndb.model):
name = StringProperty()
_helper_var = 5

Here only name is persisted to the ndb store. _helper_var is just a variable in the instance of class Person.




Python is a dynamic language, and NDB instances are similarly dynamic. At any time, you can set any attribute on a model instance, and unless it is backed up by an actual model field, it will not be saved. You don't need to declare these attributes before using them.



Using JDO in Java and App Engine one can mark an entity as being:


@NotPersistent

and essentially get use of the field during runtime, without the field attempting to be persisted during save operations to the datastore.


Does Python have an equivalent to this? Thanks!



in ndb.Model classes you can use a var starting with a underscore to mark a class variable as non-persistant.


    class Person(ndb.model):
name = StringProperty()
_helper_var = 5

Here only name is persisted to the ndb store. _helper_var is just a variable in the instance of class Person.



Python is a dynamic language, and NDB instances are similarly dynamic. At any time, you can set any attribute on a model instance, and unless it is backed up by an actual model field, it will not be saved. You don't need to declare these attributes before using them.


0 commentaires:

Enregistrer un commentaire