2023-11-18 11:57:50 +00:00
|
|
|
from rest_framework import serializers, viewsets, routers
|
|
|
|
|
|
|
|
from files.models import File
|
|
|
|
|
|
|
|
|
|
|
|
class FileSerializer(serializers.ModelSerializer):
|
|
|
|
data = serializers.CharField(max_length=1000000, write_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = File
|
|
|
|
fields = ['hash', 'data']
|
|
|
|
read_only_fields = ['hash']
|
|
|
|
|
|
|
|
|
|
|
|
class FileViewSet(viewsets.ModelViewSet):
|
|
|
|
serializer_class = FileSerializer
|
|
|
|
queryset = File.objects.all()
|
|
|
|
lookup_field = 'hash'
|
|
|
|
|
|
|
|
|
2023-11-20 14:56:32 +00:00
|
|
|
router = routers.SimpleRouter(trailing_slash=False)
|
2023-11-18 11:57:50 +00:00
|
|
|
router.register(r'files', FileViewSet, basename='files')
|
|
|
|
router.register(r'file', FileViewSet, basename='files')
|
|
|
|
|
|
|
|
urlpatterns = router.urls
|