2016-07-03 01:12:41 +00:00
|
|
|
from django.db import models
|
2016-07-03 12:02:46 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
2016-07-04 21:54:21 +00:00
|
|
|
|
2016-07-03 01:12:41 +00:00
|
|
|
|
2016-07-03 12:02:46 +00:00
|
|
|
class Switch(models.Model):
|
2016-07-03 01:12:41 +00:00
|
|
|
building = models.CharField(max_length=10)
|
2016-07-03 12:02:46 +00:00
|
|
|
number = models.IntegerField()
|
2016-07-03 01:12:41 +00:00
|
|
|
details = models.CharField(max_length=255, blank=True)
|
|
|
|
|
|
|
|
class Meta:
|
2016-07-03 12:02:46 +00:00
|
|
|
unique_together = ('building', 'number')
|
2016-07-03 01:12:41 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2016-07-03 12:02:46 +00:00
|
|
|
return str(self.building) + str(self.number)
|
2016-07-03 01:12:41 +00:00
|
|
|
|
2016-07-03 12:02:46 +00:00
|
|
|
class Port(models.Model):
|
|
|
|
switch = models.ForeignKey(Switch, related_name="ports")
|
|
|
|
port = models.IntegerField()
|
2016-07-03 01:12:41 +00:00
|
|
|
details = models.CharField(max_length=255, blank=True)
|
2016-07-03 12:02:46 +00:00
|
|
|
room = models.ForeignKey('Room', on_delete=models.PROTECT, blank=True, null=True)
|
2016-07-06 10:23:45 +00:00
|
|
|
machine_interface = models.OneToOneField('machines.Interface', on_delete=models.PROTECT, blank=True, null=True)
|
2016-07-03 12:02:46 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = ('_content_type', '_object_id')
|
|
|
|
|
|
|
|
_content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, blank=True, null=True)
|
|
|
|
_object_id = models.PositiveIntegerField(blank=True, null=True)
|
|
|
|
goto = GenericForeignKey('_content_type', '_object_id')
|
2016-07-04 21:54:21 +00:00
|
|
|
|
2016-07-03 12:02:46 +00:00
|
|
|
@property
|
|
|
|
def comefrom(self):
|
|
|
|
ctype = ContentType.objects.get_for_model(self.__class__)
|
|
|
|
try:
|
|
|
|
event = Port.objects.get(_content_type__pk=ctype.id, _object_id=self.id)
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
return event
|
2016-07-03 01:12:41 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2016-07-03 12:02:46 +00:00
|
|
|
return str(self.switch) + " - " + str(self.port)
|
2016-07-03 01:12:41 +00:00
|
|
|
|
2016-07-03 12:02:46 +00:00
|
|
|
class Room(models.Model):
|
2016-07-04 21:54:21 +00:00
|
|
|
name = models.CharField(max_length=255, unique=True)
|
2016-07-03 01:12:41 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2016-07-04 21:54:21 +00:00
|
|
|
return str(self.name)
|
2016-07-03 12:02:46 +00:00
|
|
|
|