Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base64 document handling to serializer #40

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions netbox_documents/api/fields.py
Original file line number Diff line number Diff line change
@@ -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 ''
5 changes: 5 additions & 0 deletions netbox_documents/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -13,6 +14,7 @@ class SiteDocumentSerializer(NetBoxModelSerializer):
)

site = NestedSiteSerializer()
document = UploadableBase64FileField(required=False)

class Meta:
model = SiteDocument
Expand Down Expand Up @@ -42,6 +44,7 @@ class DeviceDocumentSerializer(NetBoxModelSerializer):
)

device = NestedDeviceSerializer()
document = UploadableBase64FileField(required=False)

class Meta:
model = DeviceDocument
Expand Down Expand Up @@ -70,6 +73,7 @@ class DeviceTypeDocumentSerializer(NetBoxModelSerializer):
)

device_type = NestedDeviceTypeSerializer()
document = UploadableBase64FileField(required=False)

class Meta:
model = DeviceTypeDocument
Expand All @@ -86,6 +90,7 @@ class CircuitDocumentSerializer(NetBoxModelSerializer):
)

circuit = NestedCircuitSerializer()
document = UploadableBase64FileField(required=False)

class Meta:
model = CircuitDocument
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drf_extra_fields>=3.7.0