summaryrefslogtreecommitdiff
path: root/stats/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'stats/models.py')
-rw-r--r--stats/models.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/stats/models.py b/stats/models.py
index f2f1bce..95def40 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -13,12 +13,23 @@ class TrackLesson(models.Model):
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
current_time = models.CharField(max_length=100, default="00:00:00")
video_duration = models.CharField(max_length=100, default="00:00:00")
- last_access_time = models.DateTimeField(default=timezone.now)
creation_time = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ('user', 'course', 'lesson')
+ def get_last_access_time_and_vists(self):
+ lesson_logs = self.lessonlog_set
+ last_access_time = None
+ if lesson_logs.exists():
+ last_access_time = lesson_logs.last().last_access_time
+ return last_access_time, lesson_logs.count()
+
def __str__(self):
return (f"Track {self.lesson} in {self.course} "
f"for {self.user.get_full_name()}")
+
+
+class LessonLog(models.Model):
+ track = models.ForeignKey(TrackLesson, on_delete=models.CASCADE)
+ last_access_time = models.DateTimeField(default=timezone.now)