11432 make device field on interface read-only on api edit call

This commit is contained in:
Arthur 2023-01-23 10:47:26 -08:00
parent 53f6b9f17a
commit e72a7fa401

View File

@ -909,13 +909,16 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
return super().validate(data)
def get_extra_kwargs(self):
if self.instance:
kwargs = {'device': {'read_only': True}}
else:
kwargs = {}
def get_fields(self, *args, **kwargs):
fields = super().get_fields(*args, **kwargs)
request = self.context.get('request', None)
view = self.context.get('view', None)
return kwargs
# get_extra_kwargs doesn't work if field explicitly declared on serializer...
if (self.instance):
fields['device'].read_only = True
return fields
class RearPortSerializer(NetBoxModelSerializer, CabledObjectSerializer):