summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2020-03-12 11:08:15 +0530
committeradityacp2020-03-12 11:08:15 +0530
commit050ced8942abf802cf09e6a6f9d23d85a0be0d3f (patch)
tree45824328440bfc7d78413d4aaaca144a396cb3aa
parent9dacf7cf2a26fb0f954f6f06cfffb65e23809ab7 (diff)
downloadonline_test-050ced8942abf802cf09e6a6f9d23d85a0be0d3f.tar.gz
online_test-050ced8942abf802cf09e6a6f9d23d85a0be0d3f.tar.bz2
online_test-050ced8942abf802cf09e6a6f9d23d85a0be0d3f.zip
Avoid conditional check on foreign key
-rw-r--r--yaksh/models.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 072c1b5..065d9cd 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -598,7 +598,12 @@ class LearningUnit(models.Model):
check_prerequisite = models.BooleanField(default=True)
def get_lesson_or_quiz(self):
- return self.lesson if self.lesson else self.quiz
+ unit = None
+ if self.type == 'lesson':
+ unit = self.lesson
+ else:
+ unit = self.quiz
+ return unit
def toggle_check_prerequisite(self):
if self.check_prerequisite:
@@ -649,7 +654,12 @@ class LearningUnit(models.Model):
return new_unit
def __str__(self):
- return self.lesson.name if self.lesson else self.quiz.description
+ name = None
+ if self.type == 'lesson':
+ name = self.lesson.name
+ else:
+ name = self.quiz.description
+ return name
###############################################################################