mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-18 17:13:00 +08:00
Add patch endpoint for documents
This commit is contained in:
parent
7584f09b62
commit
9289166c0e
5 changed files with 34 additions and 7 deletions
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.1.3 on 2024-12-04 07:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("documents", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="document",
|
||||
name="document_type",
|
||||
field=models.CharField(max_length=128),
|
||||
),
|
||||
]
|
|
@ -7,7 +7,7 @@ class Document(models.Model):
|
|||
name = models.CharField(max_length=100)
|
||||
|
||||
document_type = models.CharField(
|
||||
max_length=32, null=False, blank=False
|
||||
max_length=128, null=False, blank=False
|
||||
)
|
||||
number_pages = models.IntegerField(null=False, blank=False)
|
||||
ocr_metadata = models.TextField(null=True, blank=True)
|
||||
|
|
|
@ -3,19 +3,14 @@ from .models import Document
|
|||
|
||||
|
||||
class DocumentUpdateSerializer(serializers.ModelSerializer):
|
||||
# For Head to edit document info
|
||||
file = serializers.FileField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = Document
|
||||
fields = [
|
||||
"name",
|
||||
"file",
|
||||
"document_type",
|
||||
"number_pages",
|
||||
"date_uploaded",
|
||||
]
|
||||
read_only_fields = ["id"]
|
||||
|
||||
|
||||
class DocumentUploadSerializer(serializers.ModelSerializer):
|
||||
|
|
|
@ -4,10 +4,12 @@ from .views import (
|
|||
DocumentDeleteView,
|
||||
DocumentListView,
|
||||
DocumentStaffListView,
|
||||
DocumentUpdateView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path("upload/", DocumentUploadView.as_view()),
|
||||
path("update/<int:pk>/", DocumentUpdateView.as_view()),
|
||||
path("delete/<int:pk>/", DocumentDeleteView.as_view()),
|
||||
path("list/", DocumentListView.as_view()),
|
||||
path("list/staff/", DocumentStaffListView.as_view()),
|
||||
|
|
|
@ -4,13 +4,25 @@ from .serializers import (
|
|||
DocumentFileSerializer,
|
||||
DocumentUploadSerializer,
|
||||
DocumentDeleteSerializer,
|
||||
DocumentUpdateSerializer
|
||||
)
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from accounts.permissions import IsStaff
|
||||
from accounts.permissions import IsStaff, IsHead
|
||||
from .models import Document
|
||||
|
||||
|
||||
class DocumentUpdateView(generics.UpdateAPIView):
|
||||
"""
|
||||
Used by staff to upload documents.
|
||||
"""
|
||||
|
||||
http_method_names = ["patch"]
|
||||
serializer_class = DocumentUpdateSerializer
|
||||
queryset = Document.objects.all()
|
||||
permission_classes = [IsAuthenticated, IsHead]
|
||||
|
||||
|
||||
class DocumentUploadView(generics.CreateAPIView):
|
||||
"""
|
||||
Used by staff to upload documents.
|
||||
|
|
Loading…
Reference in a new issue