Only allow one instance of a metadata type per document

This commit is contained in:
Roberto Rosario
2014-12-02 00:43:56 -04:00
parent ca847bed2c
commit 4aa84b778c
2 changed files with 62 additions and 0 deletions

View File

@@ -65,6 +65,7 @@ class DocumentMetadata(models.Model):
return super(DocumentMetadata, self).delete(*args, **kwargs)
class Meta:
unique_together = ('document', 'metadata_type')
verbose_name = _(u'Document metadata')
verbose_name_plural = _(u'Document metadata')

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as 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 'DocumentMetadata', fields ['document', 'metadata_type']
db.create_unique(u'metadata_documentmetadata', ['document_id', 'metadata_type_id'])
def backwards(self, orm):
# Removing unique constraint on 'DocumentMetadata', fields ['document', 'metadata_type']
db.delete_unique(u'metadata_documentmetadata', ['document_id', 'metadata_type_id'])
models = {
u'documents.document': {
'Meta': {'ordering': "['-date_added']", 'object_name': 'Document'},
'date_added': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'document_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'documents'", 'to': u"orm['documents.DocumentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'label': ('django.db.models.fields.CharField', [], {'default': "u'Uninitialized document'", 'max_length': '255', 'db_index': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'default': "u'eng'", 'max_length': '8'}),
'uuid': ('django.db.models.fields.CharField', [], {'default': "u'd55c3d30-544c-4ac2-90ac-112f4a4e235a'", 'max_length': '48'})
},
u'documents.documenttype': {
'Meta': {'ordering': "['name']", 'object_name': 'DocumentType'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32'}),
'ocr': ('django.db.models.fields.BooleanField', [], {'default': 'True'})
},
u'metadata.documentmetadata': {
'Meta': {'unique_together': "(('document', 'metadata_type'),)", 'object_name': 'DocumentMetadata'},
'document': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'document_metadata'", 'to': u"orm['documents.Document']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'metadata_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['metadata.MetadataType']"}),
'value': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '255', 'null': 'True', 'blank': 'True'})
},
u'metadata.documenttypemetadatatype': {
'Meta': {'unique_together': "(('document_type', 'metadata_type'),)", 'object_name': 'DocumentTypeMetadataType'},
'document_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['documents.DocumentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'metadata_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['metadata.MetadataType']"}),
'required': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
u'metadata.metadatatype': {
'Meta': {'ordering': "('title',)", 'object_name': 'MetadataType'},
'default': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'lookup': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '48'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '48'})
}
}
complete_apps = ['metadata']