Note that there are some explanatory texts on larger screens.

plurals
  1. POdon't want inner joins on django models
    primarykey
    data
    text
    <p>i've migrated an existing database that i would like to work with django. i have the following models:</p> <pre><code>class Device(models.Model): class Meta: db_table = u'DEVICES' managed=False id = models.CharField(primary_key=True, max_length=22, db_column='DEVICE_ID') name = models.CharField(max_length=40, db_column='DEVICE_NAME') status = models.CharField(max_length=10, db_column='STATUS') class DevicePort(models.Model): class Meta: db_table = u'DEVICE_PORT' managed=False id = models.CharField( primary_key=True, max_length=22, db_column='DEVICE_PORT_ID') device = models.OneToOneField(Device, db_column='DEVICE_ID') type = models.CharField( max_length=22, db_column='PORT_TYPE_ID') port_num = models.CharField( max_length=30, db_column='DEVICE_PORT_NUM') class IP(models.Model): class Meta: db_table = u'IP_NODE' managed=False ip_address = models.CharField(primary_key=True, max_length=15, db_column='IP_NODE_NO') hostname = models.CharField(max_length=40, db_column='IP_HOST') port = models.OneToOneField(DevicePort, db_column='DEVICE_PORT_ID') status = models.CharField(max_length=50, db_column='IP_NODE_STATUS') </code></pre> <p>i want a list of <code>Devices</code> and their relational <code>IP.ip_address</code> and <code>IP.hostname</code>s. In SQL, i would do something like:</p> <pre><code>SELECT UNIQUE d.device_name device FROM IP_NODE c, DEVICES d, DEVICE_PORT e WHERE c.ip_node_no = b.ip_node_no AND c.device_port_id = e.device_port_id AND e.device_id = d.device_id AND d.device_name LIKE 'something'; </code></pre> <p>How do i do this with my django models?</p>
    singulars
    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