python - Can I disallow delete queries on all instances of a resource in tastypie? -


let's have resource named res, instances accessible thourgh url: .../api/res/<res_id>/

i'd clients allowed send delete queries on specific instances (so on above url), not delete instances @ 1 time sending delete on root url resource 'res' (.../api/res/), how can configure tastypie that?

you'll have implement own authorization described in the documentation:

class customauthorization(authorization):     def delete_list(self, object_list, bundle):         raise unauthorized("you cannot delete multiple objects @ once.")         # or          return [] 

raising error return http 401 status code, while returning empty list return http 200 status code. both not delete items.

you can create subclass of of default authorization classes inherit behaviour, or can create own class , implement required methods.

edit: found out, easiest way specify list_allowed_methods attribute in resource's meta:

class myresource(models.modelresource):     class meta:         list_allowed_methods = ['get', 'post', 'put', 'patch'] # no 'delete' 

this set allowed methods requests multiple objects. it's counterpart detail_allowed_methods set allowed methods single object requests.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -