Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API post-processors #134

Open
rudimk opened this issue Apr 9, 2014 · 1 comment
Open

REST API post-processors #134

rudimk opened this issue Apr 9, 2014 · 1 comment

Comments

@rudimk
Copy link

rudimk commented Apr 9, 2014

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?

@jmtoball
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants