mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 16:06:43 -06:00
12328 update GFK object in clean
This commit is contained in:
parent
786f0cc7f3
commit
0af975e856
@ -85,11 +85,16 @@ class NetBoxModel(NetBoxFeatureSet, models.Model):
|
||||
|
||||
if ct_value and fk_value:
|
||||
klass = getattr(self, field.ct_field).model_class()
|
||||
if not klass.objects.filter(pk=fk_value).exists():
|
||||
try:
|
||||
obj = klass.objects.get(pk=fk_value)
|
||||
except ObjectDoesNotExist:
|
||||
raise ValidationError({
|
||||
field.fk_field: f"Related object not found using the provided value: {fk_value}."
|
||||
})
|
||||
|
||||
# update the GFK field value
|
||||
setattr(self, field.name, obj)
|
||||
|
||||
|
||||
#
|
||||
# NetBox internal base models
|
||||
|
Loading…
Reference in New Issue
Block a user