How to conditionally veto an attempt to remove in Django Admin 1.5?

docs clearly states that it ModelAdmin.delete_model()must remove the object and not use it for veto. The problem is that they do not give any hint on how you will use the veto if you need to.

Here is some kind of background, because maybe there is an even better way to do what I'm trying to accomplish. I grab the iptables rules in a Django 1.5 application and want to use Admin pages to handle all the maintenance. I have two models related to the problem: Chain and Target. Here is the essence of these models:

class Chain(models.Model):
    """A netfilter chain."""
    name = models.CharField(max_length=30, unique=True, primary_key=True)
    built_in = models.BooleanField(
        default=False,
        help_text=u'This option should be selected if this chain is one of '
                  u'those provided by netfilter.  Leaving this option '
                  u'unselected indicates that the chain is user-defined.'
    )
    table = models.ForeignKey(Table, verbose_name='netfilter table')

class Target(models.Model):
    """A netfilter target."""
    name = models.CharField(
        max_length=30, unique=True, primary_key=True,
        help_text=u'This may be either an iptables built-in target or a '
                  u'user-defined chain.  Built-in targets must be one of '
                  u'those supported by iptables.'
    )
    built_in = models.BooleanField(
        default=False, verbose_name='built-in',
        help_text=u'This option should be selected if this target is one of '
                  u'those provided by netfilter.  Leaving this option '
                  u'unselected indicates that the target is user-defined.',
    )

, Chain "FORWARD", "INPUT" "OUTPUT", "". , , built_in == False.

. (, ForeignKey !), (, "ACCEPT" "DROP" ), (, !).

. - , , FK, , clean_name() , , . , , Target.

+3
1

, has_delete_permission(request, obj) Chain . obj, , Targets. . .

. , delete_selected , , - . . .

+3

All Articles