Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango model -- relationships between inherited models?
    primarykey
    data
    text
    <p>I'm working on a server / datacenter inventory management tool. I have a class to define a default "device", which is then used to express custom devices (linux servers, windows servers, routers, switches, etc.)</p> <p>I also have data models set up to express IP addresses within a network.</p> <p>My question is, what would be the best way to express the relationship between all of the various device models and the ipv4 address model?</p> <pre><code>class device(models.Model): '''the primary object. all types of networked devices are based on and inherit this class''' STATUS_CHOICES = (('0', 'unknown'),('1','active'),('2','pending'),('3','inactive'),('4', 'inventory'),('5','mothballed'),('6','surplus'),) '''technical information''' hostname = models.CharField(max_length=45, unique=True, db_index=True, help_text="The published hostname for this device") '''misc. information''' description = models.TextField(blank=True, null=True, help_text="A free-form description field") type = models.ForeignKey(deviceStatus, help_text="The classification for this device") status = models.IntegerField(choices=STATUS_CHOICES, help_text="current status of device") is_monitored = models.BooleanField(default=True, help_text="is the device monitored?") date_added = models.DateTimeField(auto_now=True, help_text="Date and Time device is entered into Barrelhouse", editable=False) warranty_expriry = models.DateField(help_text="Date Manufacturer warranty expires") extended_warranty = models.BooleanField(help_text="Whether or not device has some extended warranty in addition to the manufacturer",default=False, validators=[validate_extended_warr]) ext_warranty_expiry = models.DateField(help_text="Date Extended Warranty Expires", null=True) account = models.ForeignKey(vendorAccount, help_text="account associated with this device") class Meta: abstract = True class deviceLinuxSystem(device): '''a typcial linux system --- you can get as specific as you want to in various server and desktop types.''' ip_address = generic.GenericRelation(ipv4address) def get_absolute_url(self): return "linux_devices/%i/" % self.id def __unicode__(self): return self.hostname class Meta: verbose_name = "Linux System" class deviceWindowsSystem(device): '''a typical windws system''' def get_absolute_url(self): return "windows_devices/%i/" % self.id def __unicode__(self): return self.hostname class Meta: verbose_name = "Windows System" class ipv4address(models.Model): '''a model to represent all used IPv4 addresses on networks''' netIP = models.IPAddressField(help_text="associated address", verbose_name="IP Address", unique=True, db_index=True) network = models.ForeignKey(network, help_text="Network this IP lives on") </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload