Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update models.py #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions onlinecourse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,22 @@ class Enrollment(models.Model):
# Has a grade point for each question
# Has question content
# Other fields and methods you would like to design
#class Question(models.Model):
# Foreign key to lesson
# question text
# question grade/mark

class Question(models.Model):
course = models.ForeignKey(Course, on_delete=models.CASCADE)
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
text = models.CharField(max_length=200, default="text")
mark = models.IntegerField(default=0)
# <HINT> A sample model method to calculate if learner get the score of the question
#def is_get_score(self, selected_ids):
# all_answers = self.choice_set.filter(is_correct=True).count()
# selected_correct = self.choice_set.filter(is_correct=True, id__in=selected_ids).count()
# if all_answers == selected_correct:
# return True
# else:
# return False
def is_get_score(self, selected_ids):
all_answers = self.choice_set.filter(is_correct=True).count()
selected_correct = self.choice_set.filter(is_correct=True, id__in=selected_ids).count()
if all_answers == selected_correct:
return True
else:
return False


# <HINT> Create a Choice Model with:
Expand All @@ -122,13 +125,19 @@ class Enrollment(models.Model):
# Choice content
# Indicate if this choice of the question is a correct one or not
# Other fields and methods you would like to design
# class Choice(models.Model):
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
is_correct = models.BooleanField(default=False)


# <HINT> The submission model
# One enrollment could have multiple submission
# One submission could have multiple choices
# One choice could belong to multiple submissions
#class Submission(models.Model):
# enrollment = models.ForeignKey(Enrollment, on_delete=models.CASCADE)
# choices = models.ManyToManyField(Choice)
# Other fields and methods you would like to design
class Submission(models.Model):
enrollment = models.ForeignKey(Enrollment, on_delete=models.CASCADE)
choices = models.ManyToManyField(Choice)


# Other fields and methods you would like to design