mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Category validation errors
This commit is contained in:
parent
4777b02080
commit
db45e3625f
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from rest_framework.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class Company(models.Model):
|
class Company(models.Model):
|
||||||
@ -150,7 +151,7 @@ class InvenTreeTree(models.Model):
|
|||||||
pass
|
pass
|
||||||
# Parent cannot be set to same ID (this would cause looping)
|
# Parent cannot be set to same ID (this would cause looping)
|
||||||
elif val == self.id:
|
elif val == self.id:
|
||||||
return
|
raise ValidationError("Category cannot set itself as parent")
|
||||||
# Null parent is OK
|
# Null parent is OK
|
||||||
elif val is None:
|
elif val is None:
|
||||||
pass
|
pass
|
||||||
@ -158,7 +159,7 @@ class InvenTreeTree(models.Model):
|
|||||||
else:
|
else:
|
||||||
kids = self.getUniqueChildren()
|
kids = self.getUniqueChildren()
|
||||||
if val in kids:
|
if val in kids:
|
||||||
return
|
raise ValidationError("Category cannot set a child as parent")
|
||||||
|
|
||||||
# Prohibit certain characters from tree node names
|
# Prohibit certain characters from tree node names
|
||||||
elif attrname == 'name':
|
elif attrname == 'name':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user