title: django deleting models and overriding delete method
body: <p>I have 2 models</p>
  
  <pre><code>class Vhost(models.Model):
      dns = models.ForeignKey(DNS)
      user = models.ForeignKey(User)
      extra = models.TextField()
  
  
  class ApplicationInstalled(models.Model):
      user = models.ForeignKey(User)
      added = models.DateTimeField(auto_now_add=True)
      app = models.ForeignKey(Application)
      ver = models.ForeignKey(ApplicationVersion)
      vhost = models.ForeignKey(Vhost)
      path = models.CharField(max_length=100, default="/")
  
  
      def delete(self):
  
          #
          # remove the files
          #
          print "need to remove some files"
  
  
          super(ApplicationInstalled, self).delete()
  </code></pre>
  
  <p>If I do the following</p>
  
  <pre><code>&gt;&gt;&gt; vhost = Vhost.objects.get(id=10)
  &gt;&gt;&gt; vhost.id
  10L
  &gt;&gt;&gt; ApplicationInstalled.objects.filter(vhost=vhost)
  [&lt;ApplicationInstalled: http://wiki.jy.com/&gt;]
  &gt;&gt;&gt; vhost.delete()
  &gt;&gt;&gt; ApplicationInstalled.objects.filter(vhost=vhost)
  []
  </code></pre>
  
  <p>As you can see there is an applicationinstalled object linked to vhost but when I delete the vhost, the applicationinstalled object is gone but the print never gets called.</p>
  
  <p>Any easy way to do this without iterating through the objects in the vhost delete?</p>
  
  <p><strong>Solution</strong></p>
  
  <pre><code>def delete_apps(sender, **kwargs):
      obj = kwargs['instance']
  
      print "need to delete apps"
  
  
  pre_delete.connect(delete_apps, sender=ApplicationInstalled)
  </code></pre>