I have designed an application that has an abstract base class that describes a generic device with some common fields (Name, Date, etc...) and many inherited classes that describe the protocols and the properties of them, like:
In addition I have many tables that contains the data collected over those described protocols and references the parent device, like below:
SNMP_detections (id, collected_data, datetime, parent_obj [FK to SNMP])
HTTP_detections (id, collected_data, datetime, parent_obj [FK to HTTP])
So, I was thinking about optimize the current database layout, specially the measurement tables, I'm interested in how I can use only a single table and reference from there the parent device (that can be HTTP or SNMP)...
Any suggestion?
If I understand correctly the point is to merge all specific measurement tables into a single generic one while still being able to point to the correct "device" parent record.
if yes, then multi-table inheritance might be what you're looking for.
Using multi-table inheritance you do have a single base "device" table with "common fields" (plus a distinct table with specific fields for each device subclass), so your generic "measurement" table just needs a foreignkey on the base "device" table.
The drawback is, of course, that you need some extra work to get the device's subclass data, but IIRC there are a couple of Django packages implementing this already.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.