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.
This commit is contained in:
Daniel Roschka 2015-03-22 15:47:05 +01:00
parent f0f897fad6
commit 763d132b0f
1 changed files with 26 additions and 6 deletions

View File

@ -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.