25 lines
636 B
Python
25 lines
636 B
Python
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'
|
|
|
|
|
|
router = routers.SimpleRouter()
|
|
router.register(r'files', FileViewSet, basename='files')
|
|
router.register(r'file', FileViewSet, basename='files')
|
|
|
|
urlpatterns = router.urls
|