From bcfaaf89efe9abbbc3178f90239f809d7d53f989 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 19 Feb 2019 15:23:08 +0000 Subject: [PATCH] Use IP Address Fields for IP addresses --- manager/migrations/0047_auto_20190219_1519.py | 23 +++++++++++++ manager/migrations/0048_auto_20190219_1521.py | 33 +++++++++++++++++++ manager/models.py | 8 ++--- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 manager/migrations/0047_auto_20190219_1519.py create mode 100644 manager/migrations/0048_auto_20190219_1521.py diff --git a/manager/migrations/0047_auto_20190219_1519.py b/manager/migrations/0047_auto_20190219_1519.py new file mode 100644 index 0000000..aabf825 --- /dev/null +++ b/manager/migrations/0047_auto_20190219_1519.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.5 on 2019-02-19 15:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manager', '0046_auto_20190219_1517'), + ] + + operations = [ + migrations.AlterField( + model_name='device', + name='wifi', + field=models.ManyToManyField(blank=True, to='manager.Wifi'), + ), + migrations.AlterField( + model_name='network', + name='extip', + field=models.GenericIPAddressField(protocol='ipv4', unique=True, verbose_name='External/Public IP'), + ), + ] diff --git a/manager/migrations/0048_auto_20190219_1521.py b/manager/migrations/0048_auto_20190219_1521.py new file mode 100644 index 0000000..9d31953 --- /dev/null +++ b/manager/migrations/0048_auto_20190219_1521.py @@ -0,0 +1,33 @@ +# Generated by Django 2.1.5 on 2019-02-19 15:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('manager', '0047_auto_20190219_1519'), + ] + + operations = [ + migrations.AlterField( + model_name='device', + name='curip', + field=models.GenericIPAddressField(blank=True, null=True, protocol='ipv4', verbose_name='Current IP Address'), + ), + migrations.AlterField( + model_name='device', + name='wifi', + field=models.ManyToManyField(blank=True, to='manager.Wifi'), + ), + migrations.AlterField( + model_name='network', + name='intip', + field=models.GenericIPAddressField(protocol='ipv4', unique=True, verbose_name='Internal/Private IP'), + ), + migrations.AlterField( + model_name='wifi', + name='ip', + field=models.GenericIPAddressField(blank=True, null=True, protocol='ipv4', verbose_name='Configuration IP'), + ), + ] diff --git a/manager/models.py b/manager/models.py index 0a95e54..e966020 100644 --- a/manager/models.py +++ b/manager/models.py @@ -15,8 +15,8 @@ class Organization(models.Model): class Network(models.Model): name = models.CharField("Common Name", max_length=64, blank=True, null=True) - extip = models.CharField("External/Public IP", max_length=15, unique=True) - intip = models.CharField("Internal/Private IP", max_length=15, unique=True) + extip = models.GenericIPAddressField("External/Public IP", protocol='ipv4', unique=True) + intip = models.GenericIPAddressField("Internal/Private IP", protocol='ipv4', unique=True) organization = models.ManyToManyField(Organization) def __str__(self): @@ -38,7 +38,7 @@ class Wifi(models.Model): ssid = models.CharField("WiFi SSID", max_length=32) bssid = models.CharField("WiFi BSSID", max_length=64, blank=True, null=True) key = models.CharField("WiFi key", max_length=32) - ip = models.CharField("Configuration IP", max_length=15, blank=True, null=True) + ip = models.GenericIPAddressField("Configuration IP", protocol="ipv4", blank=True, null=True) user = models.CharField("Configuration User Name", max_length=32, blank=True, null=True) password = models.CharField("Configuration Password", max_length=32, blank=True, null=True) @@ -52,7 +52,7 @@ class Device(models.Model): organization = models.ForeignKey(Organization, on_delete=models.CASCADE) network = models.ForeignKey(Network, on_delete=models.SET_NULL, blank=True, null=True) wifi = models.ManyToManyField(Wifi, blank=True) - curip = models.CharField("Current IP Address", max_length=15, blank=True, null=True) + curip = models.GenericIPAddressField("Current IP Address", protocol="ipv4", blank=True, null=True) lasttime = models.DateTimeField("Last Received IP", blank=True, null=True, editable=False) lastbeat = models.DateTimeField("Last Received Timestamp", blank=True, null=True, editable=False) secret = models.CharField("Secret", default=getRandom, max_length=128)