I am trying to write a query in Django but I'm not sure whats the best way to write this. Also assuming that the database is mySQL. This matters if distinct is used.
class Homework(models.Model):
title = TextField()
class Assignment(models.Model):
homework_id = Foreignkey(Homework, on_delete=models.CASCADE)
task = IntegerField(default=1)
version = IntegerField(default=1)
Given the models above I want to get all the assignments in a particular homework where the assignments are the latest version of the task. example:
Homework_id: 1
assignment v1, t1
assignment v2, t1
assignment v1, t2
If I have one homework object where the assignment with task 1 and assignment task 2 are in it then the result query should return Assignment t1, v2 and Assignment t2, v1
v refers to version
t refers to task