...
Code Block | ||
---|---|---|
| ||
from django.contrib.auth.models import User from django.db import models from jsonfield import JSONField NOTIFICATION_CONFIG_VERSION = 1 NOTIFICATION_CHANNEL_CONFIG = { "web": False, "push": False, "email": False, } COURSE_NOTIFICATION_CONFIG = { "discussion": { "new_post": NOTIFICATION_CHANNEL_CONFIG }, } class CourseNotificationPreferences(models.Model): """ A model to store user notification preferences. """ user = models.ForeignKey( # example: User1 User, related_name="notification_preferences", on_delete=models.CASCADE, db_index=True, help_text="User whose notification preferences are being stored.", ) course = models.CharField( # example: "course-v1:edX+DemoX+Demo_Course" max_length=255, blank=True, default=None, null=False, help_text="Course whose notification preferences are being stored.", ) notification_config = JSONField(default=COURSE_NOTIFICATION_CONFIG) preferences_version = models.BooleanField(default=1) |
The model has a unique together constraint on user and course. The notification preferences for a course will be created when a user enrolls in a course. For all existing active enrollments we plan to write a management command that will create notification preferences.
...