Let's start by adding a new data class that is going to store information about the DHCP network. This class is going to point to its "sponsor" physical network class and contains several DHCP options that are required by the clients, such as router address, DNS server, and domain name. Listing 4-1 shows what we're going to add to the models. py file.
Listing 4-1. The data model class for the DHCP subnet class DHCPNetwork(models.Model):
physical_net = models.OneToOneField(NetworkAddress) router = models.IPAddressField() dns_server = models.ForeignKey(DNSServer) domain_name = models.ForeignKey(DomainName)
return "DHCP subnet for %s" % physical_net
In this example we also refer to two new entities: DNSServer and DomainName. Classes for them are also defined in models. py and they only contain information about the IP of the DNS server(s) and domain names with brief comments. The reason for separating them from the DHCPNetwork class is that if we ever want to change the IP address of our DNS server, we won't need to go through each DHCP network entry and change it.
Was this article helpful?