I noticed that list, retrieve and update all go through the serializer to 
perform the actions but destroy does not. My guess is because in these 
cases a response of the object(s) is required. What I really want to do is 
perform some validations before deleting an object. 

I found this Stackoverflow post which touches the subject but the answers 
felt like a workarounds to me.

https://stackoverflow.com/questions/21382620/django-rest-framework-validate-before-a-delete

Currently I have 2 ways to do that,

   1. Validate in pre_delete() as suggested in SO.
   1. I feel pre_delete() is already too late to make a decision to delete 
      or not.
      2. Even though this works for now, I feel signals were not built for 
      this purpose based on the following definition from Django docs. 
   2. Validation in perform_delete() in the View.
      1. Again doesn't feel rite considering Serializers have a very nice 
      way to validate objects.
   
Django includes a “signal dispatcher” which helps allow decoupled 
> applications get notified when actions occur elsewhere in the framework. In 
> a nutshell, signals allow certain *senders* to notify a set of *receivers* 
> that 
> some action has taken place. They’re especially useful when many pieces of 
> code may be interested in the same events.



So I was curious why delete is missing in ModelSerializers? Are there any 
reasons that this is not being done? If so, then apart from the above ways 
to validate objects before deleting them are there other approaches I can 
try? 


Thanks,
Vignesh

P.S: I just started using restframework and I love it so far! 😁

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to