From dd0ba294161943dd482dfb89f6ae69c25f355fe5 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Tue, 28 Jun 2022 06:52:29 -0700 Subject: [PATCH] Use Taggit serializer for taggable models --- api/serializers.py | 4 ++-- api/tests.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index 19013ea4..e78e80c1 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -6,7 +6,7 @@ from rest_framework.exceptions import ValidationError from django.contrib.auth.models import User from django.utils import timezone -from taggit.serializers import TagListSerializerField +from taggit.serializers import TagListSerializerField, TaggitSerializer from core import models @@ -107,7 +107,7 @@ class CoreModelWithDurationSerializer(CoreModelSerializer): return attrs -class TaggableSerializer(serializers.HyperlinkedModelSerializer): +class TaggableSerializer(TaggitSerializer, serializers.HyperlinkedModelSerializer): tags = TagListSerializerField(required=False) diff --git a/api/tests.py b/api/tests.py index 1228b26c..0ed67ac7 100644 --- a/api/tests.py +++ b/api/tests.py @@ -632,6 +632,8 @@ class TagsAPITestCase(TestBase.BabyBuddyAPITestCaseBase): response = self.client.post(reverse("api:note-list"), data, format="json") self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data["tags"], data["tags"]) + note = models.Note.objects.get(pk=response.data["id"]) + self.assertEqual(list(note.tags.names()), data["tags"]) class TemperatureAPITestCase(TestBase.BabyBuddyAPITestCaseBase):