diff --git a/conntrackt/models.py b/conntrackt/models.py --- a/conntrackt/models.py +++ b/conntrackt/models.py @@ -1,8 +1,8 @@ -# Django-specific imports +# Django imports. from django.core.exceptions import ValidationError from django.db import models -# Create your models here. + class Project(models.Model): """ Implements a model with information about a project. A project has some @@ -15,8 +15,8 @@ class Project(models.Model): description - Free-form description of the project. """ - name = models.CharField(max_length = 100) - description = models.TextField(blank = True) + name = models.CharField(max_length=100) + description = models.TextField(blank=True) def __unicode__(self): """ @@ -26,6 +26,7 @@ class Project(models.Model): return self.name + class Location(models.Model): """ Implements a model with information about location. Locations can further be @@ -50,8 +51,8 @@ class Location(models.Model): description - Free-form description of a location. """ - name = models.CharField(max_length = 100) - description = models.TextField(blank = True) + name = models.CharField(max_length=100) + description = models.TextField(blank=True) def __unicode__(self): """ @@ -61,6 +62,7 @@ class Location(models.Model): return self.name + class Entity(models.Model): """ Models an entity in a project. An entity can be a server, router, or any @@ -81,8 +83,8 @@ class Entity(models.Model): located. """ - name = models.CharField(max_length = 100) - description = models.TextField(blank = True) + name = models.CharField(max_length=100) + description = models.TextField(blank=True) project = models.ForeignKey(Project) location = models.ForeignKey(Location) @@ -106,6 +108,7 @@ class Entity(models.Model): return "%s (%s - %s)" % (self.name, self.project, self.location) + class Interface(models.Model): """ Models a representation of an interface on an entity. It can be used for @@ -126,11 +129,11 @@ class Interface(models.Model): denoting the network netmask. """ - name = models.CharField(max_length = 100, default = 'eth0') - description = models.TextField(blank = True, default = 'Main network interface.') + name = models.CharField(max_length=100, default='eth0') + description = models.TextField(blank=True, default='Main network interface.') entity = models.ForeignKey(Entity) address = models.IPAddressField() - netmask = models.IPAddressField(default = '255.255.255.255') + netmask = models.IPAddressField(default='255.255.255.255') def __unicode__(self): """ @@ -145,6 +148,7 @@ class Interface(models.Model): else: return '%s (%s/%s)' % (self.entity.name, self.address, self.netmask) + class Communication(models.Model): """ Models a representation of allowed network communication. This lets the user @@ -183,11 +187,11 @@ class Communication(models.Model): ('ICMP', 'ICMP'), ) - source = models.ForeignKey(Interface, related_name = 'source_set') - destination = models.ForeignKey(Interface, related_name = 'destination_set') - protocol = models.CharField(max_length = 10, choices = PROTOCOL_CHOICES) - port = models.IntegerField(default = 0) - description = models.TextField(blank = True) + source = models.ForeignKey(Interface, related_name='source_set') + destination = models.ForeignKey(Interface, related_name='destination_set') + protocol = models.CharField(max_length=10, choices=PROTOCOL_CHOICES) + port = models.IntegerField(default=0) + description = models.TextField(blank=True) def __unicode__(self): """