Skip to content
Snippets Groups Projects
Unverified Commit 424abc03 authored by Dillon Dumesnil's avatar Dillon Dumesnil
Browse files

feat: Add User Activity Model for Course Goals AA-903

parent fa7ed70c
Branches
Tags
No related merge requests found
# Generated by Django 2.2.24 on 2021-08-13 17:02
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import opaque_keys.edx.django.models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('course_goals', '0004_auto_20210806_0137'),
]
operations = [
migrations.CreateModel(
name='UserActivity',
fields=[
('id', models.BigAutoField(primary_key=True, serialize=False)),
('course_key', opaque_keys.edx.django.models.CourseKeyField(max_length=255)),
('date', models.DateField()),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddIndex(
model_name='useractivity',
index=models.Index(fields=['user', 'course_key'], name='user_course_index'),
),
migrations.AddConstraint(
model_name='useractivity',
constraint=models.UniqueConstraint(fields=('user', 'course_key', 'date'), name='unique_user_course_date'),
),
]
......@@ -28,10 +28,10 @@ class CourseGoal(models.Model):
.. no_pii:
"""
class Meta:
app_label = "course_goals"
unique_together = ("user", "course_key")
app_label = 'course_goals'
unique_together = ('user', 'course_key')
user = models.ForeignKey(User, blank=False, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
course_key = CourseKeyField(max_length=255, db_index=True)
# The goal a user has set for the number of days they want to learn per week
days_per_week = models.PositiveIntegerField(default=0)
......@@ -46,3 +46,24 @@ class CourseGoal(models.Model):
goal=self.days_per_week,
course=self.course_key,
)
class UserActivity(models.Model):
"""
Tracks the date a user performs an activity in a course for goal purposes.
To be used in conjunction with the CourseGoal model to establish if a learner is hitting
their desired days_per_week.
To start, this model will only be tracking page views that count towards a learner's goal,
but could grow to tracking other types of goal achieving activities in the future.
.. no_pii:
"""
class Meta:
constraints = [models.UniqueConstraint(fields=['user', 'course_key', 'date'], name='unique_user_course_date')]
indexes = [models.Index(fields=['user', 'course_key'], name='user_course_index')]
id = models.BigAutoField(primary_key=True)
user = models.ForeignKey(User, on_delete=models.CASCADE)
course_key = CourseKeyField(max_length=255)
date = models.DateField()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment