title: Django Rest framework conditional delete
body: <p>[SOLVED]</p>
  
  <p>I just solved like this</p>
  
  <pre><code>class articleViewSet(viewsets.ModelViewSet):
      queryset = article.objects.all()
      serializer_class = articleSerializer
  
      def destroy(self, request, *args, **kwargs):
          password = request.data.get('password')
          article_id = request.data.get('article')
          instance = self.get_object()
          if password == instance.password:
              self.perform_destroy(instance)
              return Response(status=status.HTTP_204_NO_CONTENT)
          return Response(status=status.HTTP_304_NOT_MODIFIED)
  </code></pre>
  
  <p>And request with password parameter, it was deleted successfully.</p>
  
  <hr>
  
  <p>[delete.py]</p>
  
  <pre><code>import requests
  
  r = requests.delete("http://mysite/article/45/")
  </code></pre>
  
  <p>[views.py]</p>
  
  <pre><code>class articleViewSet(viewsets.ModelViewSet):
      queryset = article.objects.all()
      serializer_class = articleSerializer
  
      def delete(self, pk, request):
          method = self.request.method
          article = article.objects.get(pk=pk)
          if method == 'DELETE':
              if request.password == article.password:
                  article.delete()
                  return Response(status=status.HTTP_200_OK)
          return Response(status=status.HTTP_304_NOT_MODIFIED)
  </code></pre>
  
  <hr>
  
  <p>I want to add some condition when DELETE data.</p>
  
  <p>Here is my models.py and serializers.py</p>
  
  <p>[serializers.py]</p>
  
  <pre><code>class articleSerializer(serializers.ModelSerializer):
      userkey = serializers.CharField(write_only=True)
      password = serializers.CharField(write_only=True)
      class Meta:
          model = article
          fields = ('articleNo', 'content', 'date', 'userkey', 'password')
  </code></pre>
  
  <p>[models.py]</p>
  
  <pre><code>class article(models.Model):
      articleNo = models.AutoField(primary_key=True)
      userkey = models.CharField(max_length=50, null=False)
      content = models.CharField(max_length=500, null=False)
      password = models.CharField(max_length=20, null=False, default='1234')
      date = models.DateTimeField(auto_now_add=True)
  </code></pre>
  
  <p>For example, below data is in database.</p>
  
  <pre><code>| articleNo | content           | date                       | userkey |password|
  ---------------------------------------------------------------------------------
  |        33 | test article      | 2018-03-11 05:00:15.428661 | a1b2c3d4 | 1234  |
  </code></pre>
  
  <p>When "DELETE" method request, I want to compare request's password and article's password. If it is same, data will be deleted.</p>
  
  <p>Refer to document, I think I have to override <code>def delete()</code>.</p>
  
  <p>But I don't know exactly what should I do.</p>
  
  <p>How can I solve this issue?</p>
  
  <p>Thanks.</p>