2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-06 05:30:56 +00:00

Fixes for serializer validation

- Note: use the validate() function!
- Ref: https://www.django-rest-framework.org/api-guide/serializers/
- override serializer.save() functionality for simpler operation
This commit is contained in:
Oliver
2021-10-04 23:44:23 +11:00
parent 074466f087
commit 5ded23fd99
6 changed files with 99 additions and 155 deletions

View File

@ -1190,28 +1190,6 @@ class BuildItem(models.Model):
super().save()
def validate_unique(self, exclude=None):
"""
Test that this BuildItem object is "unique".
Essentially we do not want a stock_item being allocated to a Build multiple times.
"""
super().validate_unique(exclude)
items = BuildItem.objects.exclude(id=self.id).filter(
build=self.build,
stock_item=self.stock_item,
install_into=self.install_into
)
if items.exists():
msg = _("BuildItem must be unique for build, stock_item and install_into")
raise ValidationError({
'build': msg,
'stock_item': msg,
'install_into': msg
})
def clean(self):
""" Check validity of the BuildItem model.
The following checks are performed: