Changeset 6662 for trunk


Ignore:
Timestamp:
Feb 11, 2009, 11:11:20 PM (16 years ago)
Author:
andrea
Message:

extended "delete" code to unlink interfaces instead of removing them
when a linked interface is deleted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/models.py

    r6637 r6662  
    66#No need to formalize it; CHOICES don't change much
    77
    8 STATUS_CHOICES = ( 
     8STATUS_CHOICES = (
    99         ('up', 'up'),
    1010         ('dw', 'down'),
     
    5151        return self.type
    5252
     53    def delete(self):
     54        # avoid deletion, unlink interfaces
     55        # bound to the Antenna instead
     56        for i in self.interface_set.all():
     57            i.save();
     58        super(Antenna, self).delete()
     59
     60
    5361class EthernetToWifiBridge(models.Model):
    5462    type = models.CharField(max_length=10, unique=True)
     
    5664    def __unicode__(self):
    5765        return self.type
     66
     67    def delete(self):
     68        # avoid deletion, unlink interfaces
     69        # bound to the eth2wifi bridge instead
     70        for i in self.interface_set_all():
     71            i.ethernet_to_wifi = None
     72            i.save()
     73        super(EthernetToWifiBridge, self).delete()
    5874
    5975class Location(models.Model):
     
    6783    def __unicode__(self):
    6884        return self.description
    69 
    70     def delete(self):
    71         for i in self.node_set.all():
    72             i.delete()
    73         super(Location, self).delete()
     85    # overriding delete() method here is useless while we agree in
     86    # deleting all nodes within a Location on its deletion
    7487
    7588
     
    95108    def __unicode__(self):
    96109        return self.name
     110    # overriding delete() method here is useless while we agree in
     111    # deleting all nodes within a Network on its deletion
    97112
    98113class Node(models.Model):
     
    110125    def __unicode__(self):
    111126        return self.name
    112 
    113     def delete(self):
    114         for i in self.interface_set.all():
    115             i.delete
    116         super(Node, self).delete()
    117127
    118128class Interface(models.Model):
     
    158168            super(Interface, self).save(False, True)
    159169
    160 
    161170    def delete(self):
    162         #import pdb; pdb.set_trace() ;
    163         # remove reference to all other interfaces.
     171        # unlink all linked interfaces.
     172        for i in self.interface_set.all():
     173            i.link = None;
     174            i.save();
    164175        self.interface_set.clear()
    165176        super(Interface, self).delete()
Note: See TracChangeset for help on using the changeset viewer.