Add unique constraint to ProgramEnrollment model

This commit is contained in:
Alex Dusenbery
2019-04-24 12:24:09 -04:00
committed by Alex Dusenbery
parent ff07b3057e
commit bf661eaa8d
2 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-04-24 16:22
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('program_enrollments', '0002_historicalprogramcourseenrollment_programcourseenrollment'),
]
operations = [
migrations.AlterUniqueTogether(
name='programenrollment',
unique_together=set([('user', 'external_user_key', 'program_uuid', 'curriculum_uuid')]),
),
]

View File

@@ -30,6 +30,12 @@ class ProgramEnrollment(TimeStampedModel): # pylint: disable=model-missing-unic
class Meta(object):
app_label = "program_enrollments"
# A student enrolled in a given (program, curriculum) should always
# have a non-null ``user`` or ``external_user_key`` field (or both).
unique_together = (
('user', 'external_user_key', 'program_uuid', 'curriculum_uuid'),
)
user = models.ForeignKey(
User,
null=True,