Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change the status of the column in the model in django

I am creating an assignment management system, What a I want is whenever someone upload a submission in response to that assignment I want to change the status from pending, I will set everything on template page, but right now i feel like i have little issue with database.

class Assignment(models.Model):
    assignment_creator = models.ForeignKey(
        Teacher, on_delete=models.CASCADE, related_name="assignments")
    assignment_title = models.CharField(max_length=30)

class Submissions(models.Model):
    submitted_by = models.ForeignKey(Student, on_delete=models.CASCADE)
    submission_file = models.FileField(null=False, blank=True, default='')
    submitted_to = models.ForeignKey(
        Teacher, on_delete=models.CASCADE, null=True)
    submission_title = models.ForeignKey(
        Assignment, on_delete=models.CASCADE, null=True, blank=True)
    submission_status = models.BooleanField(default=False)

Is there any way to know which of the assignment related to that assignment title is uploaded so that I can change the status

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I don’ t understand your design, because when a submission is created it should already be linked with the assignment (because a student makes a submission in response of an assignment). But if you really want to set submission_title later you could override the save method:

class Assignment(models.Model):
    assignment_creator = models.ForeignKey(
        Teacher, on_delete=models.CASCADE, related_name="assignments")
    assignment_title = models.CharField(max_length=30)

class Submissions(models.Model):
    submitted_by = models.ForeignKey(Student, on_delete=models.CASCADE)
    submission_file = models.FileField(null=False, blank=True, default='')
    submitted_to = models.ForeignKey(
        Teacher, on_delete=models.CASCADE, null=True)
    submission_title = models.ForeignKey(
        Assignment, on_delete=models.CASCADE, null=True, blank=True)
    submission_status = models.BooleanField(default=False)

    def save(self, *args, **kwargs):
        if self.submission_title != None and not submission_status:
           self.submission_status = True
        super.save(*args, **kwargs)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading