diff --git a/netbox_documents/api/fields.py b/netbox_documents/api/fields.py new file mode 100644 index 0000000..c589871 --- /dev/null +++ b/netbox_documents/api/fields.py @@ -0,0 +1,7 @@ +from drf_extra_fields.fields import Base64FileField + +class UploadableBase64FileField(Base64FileField): + ALLOWED_TYPES = [''] + + def get_file_extension(self, filename, decoded_file): + return '' \ No newline at end of file diff --git a/netbox_documents/api/serializers.py b/netbox_documents/api/serializers.py index 1072ea8..c45f23c 100644 --- a/netbox_documents/api/serializers.py +++ b/netbox_documents/api/serializers.py @@ -4,6 +4,7 @@ from ..models import SiteDocument, DeviceDocument, DeviceTypeDocument, CircuitDocument from dcim.api.nested_serializers import NestedSiteSerializer, NestedDeviceSerializer, NestedDeviceTypeSerializer from circuits.api.nested_serializers import NestedCircuitSerializer +from .fields import UploadableBase64FileField # Site Document Serializer class SiteDocumentSerializer(NetBoxModelSerializer): @@ -13,6 +14,7 @@ class SiteDocumentSerializer(NetBoxModelSerializer): ) site = NestedSiteSerializer() + document = UploadableBase64FileField(required=False) class Meta: model = SiteDocument @@ -42,6 +44,7 @@ class DeviceDocumentSerializer(NetBoxModelSerializer): ) device = NestedDeviceSerializer() + document = UploadableBase64FileField(required=False) class Meta: model = DeviceDocument @@ -70,6 +73,7 @@ class DeviceTypeDocumentSerializer(NetBoxModelSerializer): ) device_type = NestedDeviceTypeSerializer() + document = UploadableBase64FileField(required=False) class Meta: model = DeviceTypeDocument @@ -86,6 +90,7 @@ class CircuitDocumentSerializer(NetBoxModelSerializer): ) circuit = NestedCircuitSerializer() + document = UploadableBase64FileField(required=False) class Meta: model = CircuitDocument diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6c647a8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +drf_extra_fields>=3.7.0 \ No newline at end of file