Search code examples
djangotastypie

Is it preferable to override the delete from API or ORM (Tastypie or Django)?


I am looking to override the delete to perform another action.

I am not sure whether I should override the obj_delete on Tastypie or override the delete function of Django. What is the best practise here and why?


Solution

  • Override it on your model if you want to prevent all of your code, whether a tastypie resource or a 3rd party Django app or otherwise, from deleting the model; override it on tastypie if you only want to change your resource behavior.

    Note: calling HTTP DELETE or PUT on a list endpoint will call the delete method of the queryset, not the delete method of each model, so you'd need to update your queryset's delete() method as well.