Commits

svevang committed 59cd3ec

unique contraint on datamoose and datoutput

  • Participants
  • Parent commits 76da38e

Comments (0)

Files changed (2)

File datamoose/migrations/0014_auto__add_unique_dataoutput_slug__add_unique_datamoose_slug.py

+# encoding: 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 'DataOutput', fields ['slug']
+        db.create_unique('datamoose_dataoutput', ['slug'])
+
+        # Removing index on 'DataMoose', fields ['slug']
+        db.delete_index('datamoose_datamoose', ['slug'])
+
+        # Adding unique constraint on 'DataMoose', fields ['slug']
+        db.create_unique('datamoose_datamoose', ['slug'])
+
+
+    def backwards(self, orm):
+        
+        # Removing unique constraint on 'DataMoose', fields ['slug']
+        db.delete_unique('datamoose_datamoose', ['slug'])
+
+        # Adding index on 'DataMoose', fields ['slug']
+        db.create_index('datamoose_datamoose', ['slug'])
+
+        # Removing unique constraint on 'DataOutput', fields ['slug']
+        db.delete_unique('datamoose_dataoutput', ['slug'])
+
+
+    models = {
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'datamoose.datainput': {
+            'Meta': {'object_name': 'DataInput'},
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}),
+            'datamoose': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'data_input_set'", 'to': "orm['datamoose.DataMoose']"}),
+            'datasource_identifier': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
+            'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.CharField', [], {'max_length': '512', 'db_index': 'True'})
+        },
+        'datamoose.datamoose': {
+            'Meta': {'object_name': 'DataMoose'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
+            'slug': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '512'})
+        },
+        'datamoose.dataoutput': {
+            'Meta': {'object_name': 'DataOutput'},
+            'accept_query_parameters': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'context_description': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
+            'css_includes': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'css_input_set'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['datamoose.DataOutput']"}),
+            'datamoose': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'data_output_set'", 'to': "orm['datamoose.DataMoose']"}),
+            'date_cached': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'javascript_assets': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['datamoose.JavascriptAsset']", 'null': 'True', 'blank': 'True'}),
+            'javascript_includes': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'javascript_input_set'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['datamoose.DataOutput']"}),
+            'mime_type': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
+            'output_cache': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'parent_template': ('django.db.models.fields.CharField', [], {'max_length': '2048'}),
+            'python_controller': ('django.db.models.fields.TextField', [], {'default': "'from math import *\\nfrom django.db import models\\nfrom django.db.models import Avg, Max, Min, Count\\n\\ndef controller(context={}):\\n\\n  return context\\n'"}),
+            'slug': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '512', 'db_index': 'True'}),
+            'template': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'datamoose.javascriptasset': {
+            'Meta': {'ordering': "['id']", 'object_name': 'JavascriptAsset'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '128'})
+        },
+        'datamoose.javascripturl': {
+            'Meta': {'ordering': "['id']", 'object_name': 'JavascriptURL'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'js_asset': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'javascript_url_set'", 'to': "orm['datamoose.JavascriptAsset']"}),
+            'url': ('django.db.models.fields.CharField', [], {'max_length': '4096'})
+        }
+    }
+
+    complete_apps = ['datamoose']

File datamoose/models.py

   name = models.CharField(max_length=512, 
                           help_text="A human friendly name for this output.\
                               basis for urls")
-  slug = models.CharField(max_length=512, db_index=True)
+  slug = models.CharField(max_length=512, unique=True)
 
   def save(self, *args, **kwargs):
     self.slug = slugify(self.name)
     verbose_name_plural = "datamoose"
 
 
-def get_io_base(related_name=None):
+def get_io_base(related_name=None, slug_unique=True):
   class InputOutputBase(models.Model):
 
     datamoose = models.ForeignKey(DataMoose, related_name=related_name)
     name = models.CharField(max_length=512, help_text="A human friendly name,\
         basis for urls")
-    slug = models.CharField(max_length=512, db_index=True)
+    slug = models.CharField(max_length=512, unique=slug_unique, db_index=True)
 
     def save(self, *args, **kwargs):
       self.slug = slugify(self.name)
 # Data Input
 #####################################################################
 
-class DataInput(get_io_base(related_name='data_input_set')):
+class DataInput(get_io_base(related_name='data_input_set', slug_unique=False)):
 
   # used as a lookup key in the datasource registry
   datasource_identifier = models.CharField(max_length=512)