Skip to content

Commit

Permalink
Add unicity constraints to the docs models.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Feb 9, 2013
1 parent 1d0d28e commit a4e34ad
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/migrations/0005_add_unicity_constaints.py
@@ -0,0 +1,46 @@
# -*- 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 'DocumentRelease', fields ['lang', 'version']
db.create_unique(u'docs_documentrelease', ['lang', 'version'])

# Adding unique constraint on 'Document', fields ['release', 'path']
db.create_unique(u'docs_document', ['release_id', 'path'])


def backwards(self, orm):
# Removing unique constraint on 'Document', fields ['release', 'path']
db.delete_unique(u'docs_document', ['release_id', 'path'])

# Removing unique constraint on 'DocumentRelease', fields ['lang', 'version']
db.delete_unique(u'docs_documentrelease', ['lang', 'version'])


models = {
u'docs.document': {
'Meta': {'unique_together': "(('release', 'path'),)", 'object_name': 'Document'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'path': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
'release': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documents'", 'to': u"orm['docs.DocumentRelease']"}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
},
u'docs.documentrelease': {
'Meta': {'unique_together': "(('lang', 'version'),)", 'object_name': 'DocumentRelease'},
'docs_subdir': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'lang': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '2'}),
'scm': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
'scm_url': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'version': ('django.db.models.fields.CharField', [], {'max_length': '20'})
}
}

complete_apps = ['docs']
6 changes: 6 additions & 0 deletions docs/models.py
Expand Up @@ -41,6 +41,9 @@ class DocumentRelease(models.Model):

objects = DocumentReleaseManager()

class Meta:
unique_together = ('lang', 'version')

def __unicode__(self):
return "%s/%s" % (self.lang, self.version)

Expand Down Expand Up @@ -78,6 +81,9 @@ class Document(models.Model):
path = models.CharField(max_length=500)
title = models.CharField(max_length=500)

class Meta:
unique_together = ('release', 'path')

def __unicode__(self):
return "/".join([self.release.lang, self.release.version, self.path])

Expand Down

0 comments on commit a4e34ad

Please sign in to comment.