Add validation to block removal of required metadata types from a document
This commit is contained in:
@@ -53,11 +53,17 @@ class DocumentMetadata(models.Model):
|
|||||||
return unicode(self.metadata_type)
|
return unicode(self.metadata_type)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
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.'))
|
raise ValidationError(_('Metadata type is not valid for this document type.'))
|
||||||
|
|
||||||
return super(DocumentMetadata, self).save(*args, **kwargs)
|
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:
|
class Meta:
|
||||||
verbose_name = _(u'Document metadata')
|
verbose_name = _(u'Document metadata')
|
||||||
verbose_name_plural = _(u'Document metadata')
|
verbose_name_plural = _(u'Document metadata')
|
||||||
|
|||||||
Reference in New Issue
Block a user