Use Taggit serializer for taggable models

This commit is contained in:
Christopher C. Wells 2022-06-28 06:52:29 -07:00 committed by Christopher Charbonneau Wells
parent 834e7636fc
commit dd0ba29416
2 changed files with 4 additions and 2 deletions

View File

@ -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)

View File

@ -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):