diff --git a/mayan/apps/metadata/models.py b/mayan/apps/metadata/models.py index 94214e0d66..e7e61b72a3 100644 --- a/mayan/apps/metadata/models.py +++ b/mayan/apps/metadata/models.py @@ -53,11 +53,17 @@ class DocumentMetadata(models.Model): return unicode(self.metadata_type) def save(self, *args, **kwargs): - if self.metadata_type not in self.document.document_type.metadata.all(): + if self.metadata_type not in self.document.document_type.metadata_type.all(): raise ValidationError(_('Metadata type is not valid for this document type.')) return super(DocumentMetadata, self).save(*args, **kwargs) + def delete(self, *args, **kwargs): + if self.metadata_type in self.document.document_type.metadata_type.filter(required=True): + raise ValidationError(_('Metadata type required if for this document type.')) + + return super(DocumentMetadata, self).delete(*args, **kwargs) + class Meta: verbose_name = _(u'Document metadata') verbose_name_plural = _(u'Document metadata')