diff --git a/topologie/__pycache__/admin.cpython-34.pyc b/topologie/__pycache__/admin.cpython-34.pyc index 6966844f..398466f3 100644 Binary files a/topologie/__pycache__/admin.cpython-34.pyc and b/topologie/__pycache__/admin.cpython-34.pyc differ diff --git a/topologie/__pycache__/models.cpython-34.pyc b/topologie/__pycache__/models.cpython-34.pyc index ebba5e08..5c9f7757 100644 Binary files a/topologie/__pycache__/models.cpython-34.pyc and b/topologie/__pycache__/models.cpython-34.pyc differ diff --git a/topologie/admin.py b/topologie/admin.py index 4a0c1b67..7c06c2e0 100644 --- a/topologie/admin.py +++ b/topologie/admin.py @@ -1,20 +1,17 @@ from django.contrib import admin -from .models import Port, Room, Link +from .models import Port, Room, Switch + +class SwitchAdmin(admin.ModelAdmin): + list_display = ('building','number','details') class PortAdmin(admin.ModelAdmin): - list_display = ('building','switch', 'port','details') + list_display = ('switch', 'port','details') class RoomAdmin(admin.ModelAdmin): - list_display = ('room','details') - -class RoomAdmin(admin.ModelAdmin): - list_display = ('room','details') - -class LinkAdmin(admin.ModelAdmin): - list_display = ('port', 'room','details') + list_display = ('building','room','number','details') admin.site.register(Port, PortAdmin) admin.site.register(Room, RoomAdmin) -admin.site.register(Link, LinkAdmin) +admin.site.register(Switch, SwitchAdmin) diff --git a/topologie/migrations/0001_initial.py b/topologie/migrations/0001_initial.py index 3f8163b9..fba57af8 100644 --- a/topologie/migrations/0001_initial.py +++ b/topologie/migrations/0001_initial.py @@ -11,25 +11,12 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='Port', + name='Switch', fields=[ - ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)), ('building', models.CharField(max_length=10)), - ('switch', models.IntegerField()), - ('port', models.IntegerField()), - ('details', models.CharField(blank=True, max_length=255)), + ('number', models.IntegerField()), + ('details', models.CharField(max_length=255, blank=True)), ], ), - migrations.CreateModel( - name='Room', - fields=[ - ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), - ('details', models.CharField(blank=True, max_length=255)), - ('room', models.CharField(max_length=255)), - ], - ), - migrations.AlterUniqueTogether( - name='port', - unique_together=set([('building', 'switch', 'port')]), - ), ] diff --git a/topologie/migrations/0002_auto_20160703_1118.py b/topologie/migrations/0002_auto_20160703_1118.py new file mode 100644 index 00000000..77ae0bff --- /dev/null +++ b/topologie/migrations/0002_auto_20160703_1118.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('topologie', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Port', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')), + ('port', models.IntegerField()), + ('details', models.CharField(max_length=255, blank=True)), + ('_object_id', models.PositiveIntegerField(null=True, blank=True)), + ('_content_type', models.ForeignKey(null=True, blank=True, to='contenttypes.ContentType')), + ('switch', models.ForeignKey(related_name='ports', to='topologie.Switch')), + ], + ), + migrations.AlterUniqueTogether( + name='port', + unique_together=set([('_content_type', '_object_id')]), + ), + ] diff --git a/topologie/migrations/0003_link.py b/topologie/migrations/0003_link.py deleted file mode 100644 index 49574716..00000000 --- a/topologie/migrations/0003_link.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('topologie', '0002_auto_20160703_0103'), - ] - - operations = [ - migrations.CreateModel( - name='Link', - fields=[ - ('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), - ('details', models.CharField(blank=True, max_length=255)), - ('port', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='topologie.Port')), - ('room', models.ForeignKey(to='topologie.Room', on_delete=django.db.models.deletion.PROTECT, blank=True)), - ], - ), - ] diff --git a/topologie/migrations/0003_room.py b/topologie/migrations/0003_room.py new file mode 100644 index 00000000..b679776d --- /dev/null +++ b/topologie/migrations/0003_room.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0002_auto_20160703_1118'), + ] + + operations = [ + migrations.CreateModel( + name='Room', + fields=[ + ('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)), + ('details', models.CharField(max_length=255, blank=True)), + ('building', models.CharField(max_length=255, unique=True)), + ('number', models.IntegerField()), + ], + ), + ] diff --git a/topologie/migrations/0004_auto_20160703_1122.py b/topologie/migrations/0004_auto_20160703_1122.py new file mode 100644 index 00000000..e4b9cb29 --- /dev/null +++ b/topologie/migrations/0004_auto_20160703_1122.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0003_room'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='switch', + unique_together=set([('building', 'number')]), + ), + ] diff --git a/topologie/migrations/0005_auto_20160703_1123.py b/topologie/migrations/0005_auto_20160703_1123.py new file mode 100644 index 00000000..6bf61b07 --- /dev/null +++ b/topologie/migrations/0005_auto_20160703_1123.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0004_auto_20160703_1122'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='room', + unique_together=set([('building', 'number')]), + ), + ] diff --git a/topologie/migrations/0006_auto_20160703_1129.py b/topologie/migrations/0006_auto_20160703_1129.py new file mode 100644 index 00000000..7b787451 --- /dev/null +++ b/topologie/migrations/0006_auto_20160703_1129.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0005_auto_20160703_1123'), + ] + + operations = [ + migrations.AddField( + model_name='room', + name='room', + field=models.IntegerField(default=1), + preserve_default=False, + ), + migrations.AlterField( + model_name='room', + name='building', + field=models.CharField(max_length=255), + ), + migrations.AlterField( + model_name='room', + name='number', + field=models.IntegerField(blank=True), + ), + migrations.AlterUniqueTogether( + name='room', + unique_together=set([('building', 'room', 'number')]), + ), + ] diff --git a/topologie/migrations/0002_auto_20160703_0103.py b/topologie/migrations/0007_auto_20160703_1148.py similarity index 66% rename from topologie/migrations/0002_auto_20160703_0103.py rename to topologie/migrations/0007_auto_20160703_1148.py index 83a290ac..498e79c8 100644 --- a/topologie/migrations/0002_auto_20160703_0103.py +++ b/topologie/migrations/0007_auto_20160703_1148.py @@ -7,13 +7,13 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('topologie', '0001_initial'), + ('topologie', '0006_auto_20160703_1129'), ] operations = [ migrations.AlterField( model_name='room', - name='room', - field=models.CharField(unique=True, max_length=255), + name='number', + field=models.IntegerField(null=True, blank=True), ), ] diff --git a/topologie/migrations/0008_port_room.py b/topologie/migrations/0008_port_room.py new file mode 100644 index 00000000..d8a8072e --- /dev/null +++ b/topologie/migrations/0008_port_room.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0007_auto_20160703_1148'), + ] + + operations = [ + migrations.AddField( + model_name='port', + name='room', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, blank=True, default=1, to='topologie.Room'), + preserve_default=False, + ), + ] diff --git a/topologie/migrations/0009_auto_20160703_1200.py b/topologie/migrations/0009_auto_20160703_1200.py new file mode 100644 index 00000000..e2935d18 --- /dev/null +++ b/topologie/migrations/0009_auto_20160703_1200.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0008_port_room'), + ] + + operations = [ + migrations.AlterField( + model_name='port', + name='room', + field=models.ForeignKey(to='topologie.Room', on_delete=django.db.models.deletion.PROTECT, blank=True, null=True), + ), + ] diff --git a/topologie/migrations/__pycache__/0001_initial.cpython-34.pyc b/topologie/migrations/__pycache__/0001_initial.cpython-34.pyc index ee411822..dd1a3024 100644 Binary files a/topologie/migrations/__pycache__/0001_initial.cpython-34.pyc and b/topologie/migrations/__pycache__/0001_initial.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0002_auto_20160703_0103.cpython-34.pyc b/topologie/migrations/__pycache__/0002_auto_20160703_0103.cpython-34.pyc deleted file mode 100644 index d397a436..00000000 Binary files a/topologie/migrations/__pycache__/0002_auto_20160703_0103.cpython-34.pyc and /dev/null differ diff --git a/topologie/migrations/__pycache__/0002_auto_20160703_1118.cpython-34.pyc b/topologie/migrations/__pycache__/0002_auto_20160703_1118.cpython-34.pyc new file mode 100644 index 00000000..945645eb Binary files /dev/null and b/topologie/migrations/__pycache__/0002_auto_20160703_1118.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0003_link.cpython-34.pyc b/topologie/migrations/__pycache__/0003_link.cpython-34.pyc deleted file mode 100644 index 763b79d8..00000000 Binary files a/topologie/migrations/__pycache__/0003_link.cpython-34.pyc and /dev/null differ diff --git a/topologie/migrations/__pycache__/0003_room.cpython-34.pyc b/topologie/migrations/__pycache__/0003_room.cpython-34.pyc new file mode 100644 index 00000000..36dc8c6e Binary files /dev/null and b/topologie/migrations/__pycache__/0003_room.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0004_auto_20160703_1122.cpython-34.pyc b/topologie/migrations/__pycache__/0004_auto_20160703_1122.cpython-34.pyc new file mode 100644 index 00000000..5a17e0f4 Binary files /dev/null and b/topologie/migrations/__pycache__/0004_auto_20160703_1122.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0005_auto_20160703_1123.cpython-34.pyc b/topologie/migrations/__pycache__/0005_auto_20160703_1123.cpython-34.pyc new file mode 100644 index 00000000..ffc76c06 Binary files /dev/null and b/topologie/migrations/__pycache__/0005_auto_20160703_1123.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0006_auto_20160703_1129.cpython-34.pyc b/topologie/migrations/__pycache__/0006_auto_20160703_1129.cpython-34.pyc new file mode 100644 index 00000000..a787a596 Binary files /dev/null and b/topologie/migrations/__pycache__/0006_auto_20160703_1129.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0007_auto_20160703_1148.cpython-34.pyc b/topologie/migrations/__pycache__/0007_auto_20160703_1148.cpython-34.pyc new file mode 100644 index 00000000..f8b8a0ce Binary files /dev/null and b/topologie/migrations/__pycache__/0007_auto_20160703_1148.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0008_port_room.cpython-34.pyc b/topologie/migrations/__pycache__/0008_port_room.cpython-34.pyc new file mode 100644 index 00000000..5974134d Binary files /dev/null and b/topologie/migrations/__pycache__/0008_port_room.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/0009_auto_20160703_1200.cpython-34.pyc b/topologie/migrations/__pycache__/0009_auto_20160703_1200.cpython-34.pyc new file mode 100644 index 00000000..91251c86 Binary files /dev/null and b/topologie/migrations/__pycache__/0009_auto_20160703_1200.cpython-34.pyc differ diff --git a/topologie/migrations/__pycache__/__init__.cpython-34.pyc b/topologie/migrations/__pycache__/__init__.cpython-34.pyc index b9761cda..5ca470a4 100644 Binary files a/topologie/migrations/__pycache__/__init__.cpython-34.pyc and b/topologie/migrations/__pycache__/__init__.cpython-34.pyc differ diff --git a/topologie/models.py b/topologie/models.py index 60060c83..c488d6f3 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -1,29 +1,53 @@ from django.db import models +from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.fields import GenericForeignKey + -class Port(models.Model): +class Switch(models.Model): building = models.CharField(max_length=10) - switch = models.IntegerField() - port = models.IntegerField() + number = models.IntegerField() details = models.CharField(max_length=255, blank=True) class Meta: - unique_together = ("building", "switch", "port") + unique_together = ('building', 'number') def __str__(self): - return str(self.building) + " - " + str(self.switch) + " - " + str(self.port) + return str(self.building) + str(self.number) + +class Port(models.Model): + switch = models.ForeignKey(Switch, related_name="ports") + port = models.IntegerField() + details = models.CharField(max_length=255, blank=True) + room = models.ForeignKey('Room', on_delete=models.PROTECT, blank=True, null=True) + + 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') + + @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 + + def __str__(self): + return str(self.switch) + " - " + str(self.port) class Room(models.Model): details = models.CharField(max_length=255, blank=True) - room = models.CharField(max_length=255, unique=True) + building = models.CharField(max_length=255) + room = models.IntegerField() + number = models.IntegerField(blank=True, null=True) + + class Meta: + unique_together = ('building', 'room', 'number') def __str__(self): - return str(self.room) + return str(self.building) + str(self.room) + '-' + str(self.number) -class Link(models.Model): - port = models.ForeignKey('Port', on_delete=models.PROTECT) - details = models.CharField(max_length=255, blank=True) - #port_linked = models.ForeignKey('Port', on_delete=models.PROTECT, blank=True) - room = models.ForeignKey('Room', on_delete=models.PROTECT, blank=True) - - def __str__(self): - return str(self.port)