mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 02:06:42 -06:00
Fixes #576: Delete all relevant CustomFieldValues ehen deleting a CustomFieldChoice
This commit is contained in:
parent
a803bd8033
commit
d049c1c244
@ -146,8 +146,10 @@ class CustomField(models.Model):
|
|||||||
# Read date as YYYY-MM-DD
|
# Read date as YYYY-MM-DD
|
||||||
return date(*[int(n) for n in serialized_value.split('-')])
|
return date(*[int(n) for n in serialized_value.split('-')])
|
||||||
if self.type == CF_TYPE_SELECT:
|
if self.type == CF_TYPE_SELECT:
|
||||||
# return CustomFieldChoice.objects.get(pk=int(serialized_value))
|
try:
|
||||||
return self.choices.get(pk=int(serialized_value))
|
return self.choices.get(pk=int(serialized_value))
|
||||||
|
except CustomFieldChoice.DoesNotExist:
|
||||||
|
return None
|
||||||
return serialized_value
|
return serialized_value
|
||||||
|
|
||||||
|
|
||||||
@ -198,6 +200,12 @@ class CustomFieldChoice(models.Model):
|
|||||||
if self.field.type != CF_TYPE_SELECT:
|
if self.field.type != CF_TYPE_SELECT:
|
||||||
raise ValidationError("Custom field choices can only be assigned to selection fields.")
|
raise ValidationError("Custom field choices can only be assigned to selection fields.")
|
||||||
|
|
||||||
|
def delete(self, using=None, keep_parents=False):
|
||||||
|
# When deleting a CustomFieldChoice, delete all CustomFieldValues which point to it
|
||||||
|
pk = self.pk
|
||||||
|
super(CustomFieldChoice, self).delete(using, keep_parents)
|
||||||
|
CustomFieldValue.objects.filter(field__type=CF_TYPE_SELECT, serialized_value=str(pk)).delete()
|
||||||
|
|
||||||
|
|
||||||
class Graph(models.Model):
|
class Graph(models.Model):
|
||||||
type = models.PositiveSmallIntegerField(choices=GRAPH_TYPE_CHOICES)
|
type = models.PositiveSmallIntegerField(choices=GRAPH_TYPE_CHOICES)
|
||||||
|
Loading…
Reference in New Issue
Block a user