mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Fix: fix notes serializing in document response
This commit is contained in:
parent
955ff32dcd
commit
777eced98f
@ -43,6 +43,7 @@ from documents.models import CustomFieldInstance
|
|||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
from documents.models import DocumentType
|
from documents.models import DocumentType
|
||||||
from documents.models import MatchingModel
|
from documents.models import MatchingModel
|
||||||
|
from documents.models import Note
|
||||||
from documents.models import PaperlessTask
|
from documents.models import PaperlessTask
|
||||||
from documents.models import SavedView
|
from documents.models import SavedView
|
||||||
from documents.models import SavedViewFilterRule
|
from documents.models import SavedViewFilterRule
|
||||||
@ -861,6 +862,20 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = ["id", "username", "first_name", "last_name"]
|
||||||
|
|
||||||
|
|
||||||
|
class NotesSerializer(serializers.ModelSerializer):
|
||||||
|
user = UserSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Note
|
||||||
|
fields = ["note", "created", "user"]
|
||||||
|
|
||||||
|
|
||||||
class DocumentSerializer(
|
class DocumentSerializer(
|
||||||
OwnedObjectSerializer,
|
OwnedObjectSerializer,
|
||||||
NestedUpdateMixin,
|
NestedUpdateMixin,
|
||||||
@ -876,6 +891,8 @@ class DocumentSerializer(
|
|||||||
created_date = serializers.DateField(required=False)
|
created_date = serializers.DateField(required=False)
|
||||||
page_count = SerializerMethodField()
|
page_count = SerializerMethodField()
|
||||||
|
|
||||||
|
notes = NotesSerializer(many=True, required=False)
|
||||||
|
|
||||||
custom_fields = CustomFieldInstanceSerializer(
|
custom_fields = CustomFieldInstanceSerializer(
|
||||||
many=True,
|
many=True,
|
||||||
allow_null=False,
|
allow_null=False,
|
||||||
|
@ -2170,8 +2170,10 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
GIVEN:
|
GIVEN:
|
||||||
- A document with a single note
|
- A document with a single note
|
||||||
WHEN:
|
WHEN:
|
||||||
|
- API request for document
|
||||||
- API request for document notes is made
|
- API request for document notes is made
|
||||||
THEN:
|
THEN:
|
||||||
|
- Note is included in the document response
|
||||||
- The associated note is returned
|
- The associated note is returned
|
||||||
"""
|
"""
|
||||||
doc = Document.objects.create(
|
doc = Document.objects.create(
|
||||||
@ -2185,6 +2187,18 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
user=self.user,
|
user=self.user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
response = self.client.get(
|
||||||
|
f"/api/documents/{doc.pk}/",
|
||||||
|
format="json",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
resp_data = response.json()
|
||||||
|
self.assertEqual(len(resp_data["notes"]), 1)
|
||||||
|
self.assertEqual(resp_data["notes"][0]["note"], note.note)
|
||||||
|
self.assertEqual(resp_data["notes"][0]["user"]["username"], self.user.username)
|
||||||
|
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
f"/api/documents/{doc.pk}/notes/",
|
f"/api/documents/{doc.pk}/notes/",
|
||||||
format="json",
|
format="json",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user