开发者

Django query for many-to-one relation with no instances of the foreign-key relationship

开发者 https://www.devze.com 2023-04-13 06:31 出处:网络
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 n

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号