diff --git a/mayan/apps/metadata/models.py b/mayan/apps/metadata/models.py index b73100878b..38d8c53214 100644 --- a/mayan/apps/metadata/models.py +++ b/mayan/apps/metadata/models.py @@ -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') diff --git a/mayan/apps/metadata/south_migrations/0010_auto__add_unique_documentmetadata_document_metadata_type.py b/mayan/apps/metadata/south_migrations/0010_auto__add_unique_documentmetadata_document_metadata_type.py new file mode 100644 index 0000000000..289d5c53be --- /dev/null +++ b/mayan/apps/metadata/south_migrations/0010_auto__add_unique_documentmetadata_document_metadata_type.py @@ -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'] \ No newline at end of file