mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
api changes.
This commit is contained in:
parent
62cc4a7a54
commit
68c233005e
@ -79,11 +79,15 @@ class DocumentTypeField(serializers.PrimaryKeyRelatedField):
|
||||
|
||||
class DocumentSerializer(serializers.ModelSerializer):
|
||||
|
||||
correspondent_id = CorrespondentField(
|
||||
allow_null=True, source='correspondent')
|
||||
tags_id = TagsField(many=True, source='tags')
|
||||
document_type_id = DocumentTypeField(
|
||||
allow_null=True, source='document_type')
|
||||
correspondent = CorrespondentField(allow_null=True)
|
||||
tags = TagsField(many=True)
|
||||
document_type = DocumentTypeField(allow_null=True)
|
||||
|
||||
correspondent_object = TagSerializer(
|
||||
read_only=True, source="correspondent")
|
||||
document_type_object = TagSerializer(
|
||||
read_only=True, source="document_type")
|
||||
tags_objects = TagSerializer(many=True, read_only=True, source="tags")
|
||||
|
||||
class Meta:
|
||||
model = Document
|
||||
@ -91,13 +95,13 @@ class DocumentSerializer(serializers.ModelSerializer):
|
||||
fields = (
|
||||
"id",
|
||||
"correspondent",
|
||||
"correspondent_id",
|
||||
"correspondent_object",
|
||||
"document_type",
|
||||
"document_type_id",
|
||||
"document_type_object",
|
||||
"title",
|
||||
"content",
|
||||
"tags",
|
||||
"tags_id",
|
||||
"tags_objects",
|
||||
"created",
|
||||
"modified",
|
||||
"added",
|
||||
|
@ -41,20 +41,20 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
|
||||
returned_doc = response.data['results'][0]
|
||||
self.assertEqual(returned_doc['id'], doc.id)
|
||||
self.assertEqual(returned_doc['title'], doc.title)
|
||||
self.assertEqual(returned_doc['correspondent']['name'], c.name)
|
||||
self.assertEqual(returned_doc['document_type']['name'], dt.name)
|
||||
self.assertEqual(returned_doc['correspondent']['id'], c.id)
|
||||
self.assertEqual(returned_doc['document_type']['id'], dt.id)
|
||||
self.assertEqual(returned_doc['correspondent']['id'], returned_doc['correspondent_id'])
|
||||
self.assertEqual(returned_doc['document_type']['id'], returned_doc['document_type_id'])
|
||||
self.assertEqual(returned_doc['correspondent_object']['name'], c.name)
|
||||
self.assertEqual(returned_doc['document_type_object']['name'], dt.name)
|
||||
self.assertEqual(returned_doc['correspondent_object']['id'], c.id)
|
||||
self.assertEqual(returned_doc['document_type_object']['id'], dt.id)
|
||||
self.assertEqual(returned_doc['correspondent_object']['id'], returned_doc['correspondent'])
|
||||
self.assertEqual(returned_doc['document_type_object']['id'], returned_doc['document_type'])
|
||||
self.assertEqual(len(returned_doc['tags']), 1)
|
||||
self.assertEqual(returned_doc['tags'][0]['name'], tag.name)
|
||||
self.assertEqual(returned_doc['tags'][0]['id'], tag.id)
|
||||
self.assertListEqual(returned_doc['tags_id'], [tag.id])
|
||||
self.assertEqual(returned_doc['tags_objects'][0]['name'], tag.name)
|
||||
self.assertEqual(returned_doc['tags_objects'][0]['id'], tag.id)
|
||||
self.assertListEqual(returned_doc['tags'], [tag.id])
|
||||
|
||||
c2 = Correspondent.objects.create(name="c2")
|
||||
|
||||
returned_doc['correspondent_id'] = c2.pk
|
||||
returned_doc['correspondent'] = c2.pk
|
||||
returned_doc['title'] = "the new title"
|
||||
|
||||
response = self.client.put('/api/documents/{}/'.format(doc.pk), returned_doc, format='json')
|
||||
|
Loading…
x
Reference in New Issue
Block a user