diff options
author | Palaparthy Adityachandra | 2020-11-07 19:07:36 +0530 |
---|---|---|
committer | GitHub | 2020-11-07 19:07:36 +0530 |
commit | 39a13424ad5b5d59044bec27530bdad1ccf12c25 (patch) | |
tree | 886f3277e1f2399eafa8ff596c72c904aaae18f8 /stats/models.py | |
parent | 5d320e054cd125582c56a6c25a70ba57f1cccbce (diff) | |
parent | d09ff51b6c957137e705fee73f1808c6333eed7f (diff) | |
download | online_test-39a13424ad5b5d59044bec27530bdad1ccf12c25.tar.gz online_test-39a13424ad5b5d59044bec27530bdad1ccf12c25.tar.bz2 online_test-39a13424ad5b5d59044bec27530bdad1ccf12c25.zip |
Merge pull request #794 from adityacp/video_tracking
Basic tracking for video lessons
Diffstat (limited to 'stats/models.py')
-rw-r--r-- | stats/models.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/stats/models.py b/stats/models.py new file mode 100644 index 0000000..95def40 --- /dev/null +++ b/stats/models.py @@ -0,0 +1,35 @@ +# Django Imports +from django.db import models +from django.utils import timezone +from django.contrib.auth.models import User + +# Local Imports +from yaksh.models import Course, Lesson + + +class TrackLesson(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + course = models.ForeignKey(Course, on_delete=models.CASCADE) + 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") + 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) |