diff options
author | adityacp | 2018-01-08 17:40:40 +0530 |
---|---|---|
committer | adityacp | 2018-01-08 17:40:40 +0530 |
commit | f98684da14deb2bbf76088323bc4cf8075026896 (patch) | |
tree | b3b923d5b5ec80f05ea81194522509eb06154eb5 /yaksh/models.py | |
parent | feb295b4107a95621e9430f5c7042cfde4674cc0 (diff) | |
download | online_test-f98684da14deb2bbf76088323bc4cf8075026896.tar.gz online_test-f98684da14deb2bbf76088323bc4cf8075026896.tar.bz2 online_test-f98684da14deb2bbf76088323bc4cf8075026896.zip |
Change in models.py and views.py
- Add new model method for course to check last unit and get next module
- Change views to allow student to redirect to next module
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 1d24bda..208c855 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -668,6 +668,19 @@ class Course(models.Model): module.learning_unit.all().delete() learning_modules.delete() + def is_last_unit(self, module, unit_id): + last_unit = module.get_learning_units().last() + return unit_id == last_unit.id + + def next_module(self, current_module_id): + modules = self.get_learning_modules() + module_ids = list(modules.values_list("id", flat=True)) + current_unit_index = module_ids.index(current_module_id) + next_index = current_unit_index + 1 + if next_index == len(module_ids): + next_index = 0 + return modules.get(id=module_ids[next_index]) + def __str__(self): return self.name |