diff options
| author | 2021-05-31 15:27:54 +0530 | |
|---|---|---|
| committer | 2021-05-31 15:27:54 +0530 | |
| commit | 28de14b671cf5c80b08044806b154e6272d86d2c (patch) | |
| tree | a66bdfa6a73b4287a228c933767496ee153bdf76 | |
| parent | Use ModelViewSet to add support for PUT and PATCH request. (diff) | |
Return a list of ot-names only for GET request only to bot/off-topic-channel-names
| -rw-r--r-- | pydis_site/apps/api/serializers.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 8f61073e..e09c383e 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -200,14 +200,29 @@ class ExpandedInfractionSerializer(InfractionSerializer): return ret +class OffTopicChannelNameListSerializer(ListSerializer): + def update(self, instance, validated_data): + pass + + def to_representation(self, obj: OffTopicChannelName) -> str: + """ + Return the representation of this `OffTopicChannelName`. + This only returns the name of the off topic channel name. As the model + only has a single attribute, it is unnecessary to create a nested dictionary. + Additionally, this allows off topic channel name routes to simply return an + array of names instead of objects, saving on bandwidth. + """ + return obj.name + + class OffTopicChannelNameSerializer(ModelSerializer): """A class providing (de-)serialization of `OffTopicChannelName` instances.""" class Meta: """Metadata defined for the Django REST Framework.""" - + list_serializer_class = OffTopicChannelNameListSerializer model = OffTopicChannelName - fields = ('name', 'active') + fields = ('name', 'used', 'active') class ReminderSerializer(ModelSerializer): |