Python NDB: Property validation in queries? -


i have model:

def category_path_validator(prop , val):     # makes sure path of form `first.second(...)last`     # , represents valid path in category tree.     pass  class product(ndb.model):     category_path = nsb.stringproperty(validator=category_path_validator) 

i want able products within category query is:

product.query(ndb.and(product.category_path >= 'furniture' , product.category_path <= 'furniturez')) 

(adding z works since <=,>= compares strings lexicography )

now produces error because furniturez not valid category.

is there way query value without validation , still able set property with validation ?

i think best way split validation 2 parts. first part simplify validator check stringproperty:

def category_path_validator(prop , val):     # makes sure path of form `first.second(...)last`     pass 

the second part add model hook:

def _pre_put_hook(self):     # makes sure category_path represents valid path in category tree.     pass 

the downside won't know if category_path bad until try , put() it.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -