Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add unicity constraints to the docs models.

  • Loading branch information...
commit a4e34ad48767bbbdf46e2dc265bc816c8f632b91 1 parent 1d0d28e
Aymeric Augustin authored February 09, 2013
46  docs/migrations/0005_add_unicity_constaints.py
... ...
@@ -0,0 +1,46 @@
  1
+# -*- coding: utf-8 -*-
  2
+import datetime
  3
+from south.db import db
  4
+from south.v2 import SchemaMigration
  5
+from django.db import models
  6
+
  7
+
  8
+class Migration(SchemaMigration):
  9
+
  10
+    def forwards(self, orm):
  11
+        # Adding unique constraint on 'DocumentRelease', fields ['lang', 'version']
  12
+        db.create_unique(u'docs_documentrelease', ['lang', 'version'])
  13
+
  14
+        # Adding unique constraint on 'Document', fields ['release', 'path']
  15
+        db.create_unique(u'docs_document', ['release_id', 'path'])
  16
+
  17
+
  18
+    def backwards(self, orm):
  19
+        # Removing unique constraint on 'Document', fields ['release', 'path']
  20
+        db.delete_unique(u'docs_document', ['release_id', 'path'])
  21
+
  22
+        # Removing unique constraint on 'DocumentRelease', fields ['lang', 'version']
  23
+        db.delete_unique(u'docs_documentrelease', ['lang', 'version'])
  24
+
  25
+
  26
+    models = {
  27
+        u'docs.document': {
  28
+            'Meta': {'unique_together': "(('release', 'path'),)", 'object_name': 'Document'},
  29
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  30
+            'path': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
  31
+            'release': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documents'", 'to': u"orm['docs.DocumentRelease']"}),
  32
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
  33
+        },
  34
+        u'docs.documentrelease': {
  35
+            'Meta': {'unique_together': "(('lang', 'version'),)", 'object_name': 'DocumentRelease'},
  36
+            'docs_subdir': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
  37
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  38
+            'is_default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  39
+            'lang': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}),
  40
+            'scm': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
  41
+            'scm_url': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
  42
+            'version': ('django.db.models.fields.CharField', [], {'max_length': '20'})
  43
+        }
  44
+    }
  45
+
  46
+    complete_apps = ['docs']
6  docs/models.py
@@ -41,6 +41,9 @@ class DocumentRelease(models.Model):
41 41
 
42 42
     objects = DocumentReleaseManager()
43 43
 
  44
+    class Meta:
  45
+        unique_together = ('lang', 'version')
  46
+
44 47
     def __unicode__(self):
45 48
         return "%s/%s" % (self.lang, self.version)
46 49
 
@@ -78,6 +81,9 @@ class Document(models.Model):
78 81
     path = models.CharField(max_length=500)
79 82
     title = models.CharField(max_length=500)
80 83
 
  84
+    class Meta:
  85
+        unique_together = ('release', 'path')
  86
+
81 87
     def __unicode__(self):
82 88
         return "/".join([self.release.lang, self.release.version, self.path])
83 89
 

0 notes on commit a4e34ad

Please sign in to comment.
Something went wrong with that request. Please try again.