title: Possible to do conditional ForeignKey.on_delete in Django?
body: <p>Through the <a href="https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.on_delete" rel="noreferrer">on_delete option, Django provides various alternatives</a> for what to do with objects that have a foreign key to an object that is being deleted.</p>
  
  <p>I'm wondering if there is a way I could do something similar, but conditionally. Here's the scenario. I am utilizing Django 1.5's new custom User model and all my users have a ForeignKey to Site. Like so:</p>
  
  <pre><code>class TenantSiteUser(AbstractUser):
    site = models.ForeignKey(Site, null=True)
  </code></pre>
  
  <p>If a site is deleted, then I'd prefer to delete all the non-superusers linked to that site (i.e., KASKADE-like behavoir), since their existence is now meaningless.  But if its a superuser, I'd prefer to just set the user's site to null (i.e., SET_NULL) and let them keep existing, since that's probably me or someone I work with and we tend to not want to unintentionally delete ourselves.  </p>
  
  <p>Is there something I can override to manually do a check and implement this type of on_delete behavior?</p>
  
  <p>EDIT: Here's the code that ended up working for me, based on @Kevin's answer and some study of how the existing handlers work:</p>
  
  <pre><code>def NULLIFY_SUPERUSERS_ELSE_CASCADE(collector, field, sub_objs, using):
      superusers = []
      for user in sub_objs:
          if user.is_superuser:
              sub_objs = list(sub_objs)
              sub_objs.remove(user)
              superusers.append(user)
  
      CASCADE(collector, field, sub_objs, using)
      if len(superusers):
          collector.add_field_update(field, None, superusers)
  
  class TenantSiteUser(AbstractUser):
      site = models.ForeignKey(Site, null=True, on_delete=NULLIFY_SUPERUSERS_ELSE_CASCADE)
  </code></pre>