X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/656ceadd4ab204cb994817d604ef968845fd6964..54431b5080c621c05714ccfc1accca816aeff2fc:/catalogue/models.py diff --git a/catalogue/models.py b/catalogue/models.py index ee0222c..f1c5377 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -173,6 +173,24 @@ class Lesson(models.Model): def get_syntetic(self): return self.section.syntetic_lesson(self.level) + def get_previous(self): + if self.section is None: return None + try: + return self.section.lesson_set.filter( + type=self.type, level=self.level, + order__lt=self.order).order_by('-order')[0] + except IndexError: + return None + + def get_next(self): + if self.section is None: return None + try: + return self.section.lesson_set.filter( + type=self.type, level=self.level, + order__gt=self.order).order_by('order')[0] + except IndexError: + return None + class Attachment(models.Model): slug = models.CharField(max_length=255)