porting to ndb, question on repeated=true and _validate/_to_base_type

28 views
Skip to first unread message

Tom Willis

unread,
Mar 29, 2012, 10:30:43 AM3/29/12
to google-a...@googlegroups.com
Glad to discover that there's a group for ndb. 


In our application we had sub-classed StringListProperty to insure that the values in the list were unique simply by doing

    def get_value_for_datastore(self, model_instance):
        #dedupe the underlying list
        lst = list(set(super(UniqueStringListProperty,
                   self).get_value_for_datastore(model_instance)))
        #normalize it and return
        return [x.strip().lower() for x in lst if x is not None \
                and len(x.strip()) > 0]


So I can't figure out how to do this in ndb since _to_base_type gets a single value out of the list at a time. 

I suppose it is possible to put this behavior on the class, but we use this a lot so I was wondering if there is any mechanism on Properties for validation/conversion that operates on all the items at once?


Any ideas?


Thanks In Advance

Tom

Tom Willis

unread,
Mar 29, 2012, 10:31:37 AM3/29/12
to google-a...@googlegroups.com
geez, and I should actually post to the right group. sorry for the noise everyone.
Reply all
Reply to author
Forward
0 new messages