flask-peewee
flask-peewee copied to clipboard
REST API post-processors
When a request(GET/POST) is made to a model using the in-built API module, can one execute a post-processor? For instance, if I have a City model, and I make a POST request to add a new user, which then fires up a function to, say, get the city's co-ordinates from the Google Maps API?
Might be a bit late now, but you could subclass RestResource and override create like so:
class PostSaveResource(RestResource):
def save_object(self, instance, raw_data):
saved_instance = super(PostSaveResource, self).save_object(instance, raw_data)
#Do whatever you need to with the instance here
return saved_instance
Note that the same method is also called on saving existing instances, not just new ones. There are separate edit and create-methods, but you'd have to duplicate them partially to get hold of the instance and not just the response object.