From 49bc5a2de163e753dcc347bc5570e6a9a8dfd661 Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Mon, 6 Jan 2014 15:43:11 -0500 Subject: [PATCH] Enforce school hashtag uniqueness #239 --- .../0005_auto__add_unique_school_hashtag.py | 53 +++++++++++++++++++ karmaworld/apps/courses/models.py | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 karmaworld/apps/courses/migrations/0005_auto__add_unique_school_hashtag.py diff --git a/karmaworld/apps/courses/migrations/0005_auto__add_unique_school_hashtag.py b/karmaworld/apps/courses/migrations/0005_auto__add_unique_school_hashtag.py new file mode 100644 index 0000000..6ced7b7 --- /dev/null +++ b/karmaworld/apps/courses/migrations/0005_auto__add_unique_school_hashtag.py @@ -0,0 +1,53 @@ +# -*- 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 'School', fields ['hashtag'] + db.create_unique('courses_school', ['hashtag']) + + + def backwards(self, orm): + # Removing unique constraint on 'School', fields ['hashtag'] + db.delete_unique('courses_school', ['hashtag']) + + + models = { + 'courses.course': { + 'Meta': {'ordering': "['-file_count', 'school', 'name']", 'unique_together': "(('school', 'name', 'instructor_name'),)", 'object_name': 'Course'}, + 'academic_year': ('django.db.models.fields.IntegerField', [], {'default': '2014', 'null': 'True', 'blank': 'True'}), + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'desc': ('django.db.models.fields.TextField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'instructor_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'instructor_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}) + }, + 'courses.school': { + 'Meta': {'ordering': "['-file_count', '-priority', 'name']", 'object_name': 'School'}, + 'alias': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'hashtag': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'priority': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'blank': 'True'}), + 'usde_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['courses'] \ No newline at end of file diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index d18e7d6..17a2758 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -28,7 +28,7 @@ class School(models.Model): file_count = models.IntegerField(default=0) priority = models.BooleanField(default=0) alias = models.CharField(max_length=255, null=True, blank=True) - hashtag = models.CharField(max_length=16, null=True, blank=True, help_text='School abbreviation without #') + hashtag = models.CharField(max_length=16, null=True, blank=True, unique=True, help_text='School abbreviation without #') class Meta: """ Sort School by file_count descending, name abc=> """ -- 2.25.1