title: Edit record before delete. Django DeleteView
body: <p>I have the follow models:</p>
  
  <pre><code>class Category(models.Model):
      ....
      posts = models.PositiveIntegerField(_('numero post'), default=0)
      ....
  
  class Post(models.Model):
      ....
      categories = models.ManyToManyField(Category, blank=True, verbose_name=_('categorie'))
      ....
  </code></pre>
  
  <p>the <code>Category.posts</code> field counts the number of the posts related to it's own category. I increase the counter into the <code>CreateView</code> in the following way:</p>
  
  <pre><code>class CreatePostView(LoginRequiredMixin, CreateView):
      model = Post
      ...
  
      def form_valid(self, form, **kwargs):
          ...
          categories = self.object.categories.all()
          for category in categories:
              category.posts = category.posts + 1
              category.save()
  
          self.object.save()
          return super(CreatePostView, self).form_valid(form)
  </code></pre>
  
  <p>Whene i delete the blog post i need to decrement the counter when the <code>Post</code> is deleted. I've tried to do in this way:</p>
  
  <pre><code>class DeletePostView(LoginRequiredMixin, DeleteView):
      model = Post
      ...
  
      def form_valid(self, form, **kwargs):
          ...
          categories = post.categories.all()
          for category in categories:
              if (category.posts - 1) &gt; 0:
                  category.posts = category.posts - 1
                  category.save()
          return post
  </code></pre>
  
  <p>But it doesn't work, because the record is deleted before that this method is called.</p>
  
  <p>How can i do this operation before that the record is deleted?
  Or there is a built-in way to get the number of related records from <code>Category</code>?</p>