I am having difficulties changing the following MySQL Query to a Django Query
SELECT * FROM dashboard_db.dashboard_system ds
JOIN dashboard_db.dashboard_userpreference up
ON ds.id = up.system_id
WHERE username = "<user>"
Here are the models in my Django application
class System(models.Model):
system_name = models.CharField(max_length = 40)
LOCATION = (('0', 'Inernal'),('1','External'))
location = models.CharField(max_length=1, choices=LOCATION)
def __str__(self):
return self.system_name
class UserPreference(models.Model):
username = models.CharField(max_length = 40)
system = models.ForeignKey(System, on_delete = models.CASCADE)
def __str__(self):
return self.username
I have been trying to use unions and a few other options. I am aware that Performing a raw SQL query is an option. However I was wondering if it is possible to perform the join using a Django styled query.
Systems for which the correspondingUserPreferenceusernameis a given username?