From 763d132b0f01a032609b425c2d4d191ccd3ef69a Mon Sep 17 00:00:00 2001 From: Daniel Roschka Date: Sun, 22 Mar 2015 15:47:05 +0100 Subject: [PATCH] Some small improvements for the models. * Added help texts to all fields to make adding servers and keys in the admin interface more convenient. * Added a default ordering for servers and keys. * Added unique constraints, so there can be only on key per name and one server per hostname as this has already already been an implicit constraint in the code. --- binder/models.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/binder/models.py b/binder/models.py index d41b33c..8b624b3 100644 --- a/binder/models.py +++ b/binder/models.py @@ -26,13 +26,22 @@ class Key(models.Model): TODO: Should/Can we encrypt these DNS keys in the DB? """ - name = models.CharField(max_length=255) - data = models.CharField(max_length=255) - algorithm = models.CharField(max_length=255, choices=TSIG_ALGORITHMS) + name = models.CharField(max_length=255, + unique=True, + help_text="A human readable name for the key to store, used for " + "further references to the key.") + data = models.CharField(max_length=255, + help_text="The private part of the TSIG key.") + algorithm = models.CharField(max_length=255, + choices=TSIG_ALGORITHMS, + help_text="The algorithm which has been used for the key.") def __unicode__(self): return self.name + class Meta: + ordering = ["name"] + def create_keyring(self): if self.name is None: return None @@ -52,13 +61,24 @@ class BindServer(models.Model): statistics ports. Also reference FK for TSIG transfer keys, if required. """ - hostname = models.CharField(max_length=255) - statistics_port = models.IntegerField() - default_transfer_key = models.ForeignKey(Key, null=True, blank=True) + hostname = models.CharField(max_length=255, + unique=True, + help_text="Host name or IP address of the BIND server.") + statistics_port = models.IntegerField(help_text="Port where the BIND server is serving " + "statistics on.") + default_transfer_key = models.ForeignKey(Key, + null=True, + blank=True, + help_text="The default key to use for all actions " + "with this DNS server as long as no other key is " + "specified explicitly.") def __unicode__(self): return self.hostname + class Meta: + ordering = ["hostname"] + def list_zones(self): """ List the DNS zones and attributes.