Django query for many-to-one relation with no instances of the foreign-key relationship
I have a many-to-one relationship between submissions and assignments (a student may have multiple submissions for a single assignment). I would like to create a query that shows the assignments with no associated submissions.
My models.py includes:
class Assignment(model.Model):
student=models.ForeignKey("Student")
timeStarted=models.DateTimeField(null=True)
class Submission(models.Model):
assignment=models.ForeignKey("Assignment")
timeSubmitted=models.DateTimeField(auto_now_add=True)
answerFile=models.FileField(upload_to="开发者_运维技巧/%Y/%m/%d")
Thank you for any help for the syntax for this query.
Assignment.objects.filter(submission__isnull=True)
精彩评论