From af76997ccd74fb697e8df52bf6c62d5b59d1c406 Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Fri, 16 Aug 2013 15:26:57 -0400 Subject: [PATCH] Add in a uniqueness constraint on mode, course, and currency. --- ...coursemode_course_id_currency_mode_slug.py | 33 +++++++++++++++++++ lms/djangoapps/course_modes/models.py | 4 +++ 2 files changed, 37 insertions(+) create mode 100644 lms/djangoapps/course_modes/migrations/0003_auto__add_unique_coursemode_course_id_currency_mode_slug.py diff --git a/lms/djangoapps/course_modes/migrations/0003_auto__add_unique_coursemode_course_id_currency_mode_slug.py b/lms/djangoapps/course_modes/migrations/0003_auto__add_unique_coursemode_course_id_currency_mode_slug.py new file mode 100644 index 0000000000..56a4f28c57 --- /dev/null +++ b/lms/djangoapps/course_modes/migrations/0003_auto__add_unique_coursemode_course_id_currency_mode_slug.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding unique constraint on 'CourseMode', fields ['course_id', 'currency', 'mode_slug'] + db.create_unique('course_modes_coursemode', ['course_id', 'currency', 'mode_slug']) + + + def backwards(self, orm): + # Removing unique constraint on 'CourseMode', fields ['course_id', 'currency', 'mode_slug'] + db.delete_unique('course_modes_coursemode', ['course_id', 'currency', 'mode_slug']) + + + models = { + 'course_modes.coursemode': { + 'Meta': {'unique_together': "(('course_id', 'mode_slug', 'currency'),)", 'object_name': 'CourseMode'}, + 'course_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'currency': ('django.db.models.fields.CharField', [], {'default': "'usd'", 'max_length': '8'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'min_price': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'mode_display_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'mode_slug': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'suggested_prices': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}) + } + } + + complete_apps = ['course_modes'] \ No newline at end of file diff --git a/lms/djangoapps/course_modes/models.py b/lms/djangoapps/course_modes/models.py index 347094880b..561c078b3b 100644 --- a/lms/djangoapps/course_modes/models.py +++ b/lms/djangoapps/course_modes/models.py @@ -34,6 +34,10 @@ class CourseMode(models.Model): DEFAULT_MODE = Mode('honor', _('Honor Code Certificate'), 0, '', 'usd') + class Meta: + """ meta attributes of this model """ + unique_together = ('course_id', 'mode_slug', 'currency') + @classmethod def modes_for_course(cls, course_id): """