From 6db31c4ed070c88ddd435f5ff6a251e136921b90 Mon Sep 17 00:00:00 2001 From: jerabekjiri Date: Mon, 16 Oct 2023 16:20:18 +0200 Subject: [PATCH] add count to TagSerializer fixes: #1612 --- CHANGES/1612.feature | 1 + pulp_ansible/app/serializers.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 CHANGES/1612.feature diff --git a/CHANGES/1612.feature b/CHANGES/1612.feature new file mode 100644 index 000000000..95e729dfb --- /dev/null +++ b/CHANGES/1612.feature @@ -0,0 +1 @@ +Display the ``count`` attribute in the tags of collections. diff --git a/pulp_ansible/app/serializers.py b/pulp_ansible/app/serializers.py index 4aa93a1a4..443e21dcc 100644 --- a/pulp_ansible/app/serializers.py +++ b/pulp_ansible/app/serializers.py @@ -385,9 +385,14 @@ class TagSerializer(serializers.ModelSerializer): A serializer for the Tag model. """ + count = serializers.SerializerMethodField() + + def get_count(self, obj): + return obj.ansible_collectionversion.count() + class Meta: model = Tag - fields = ["name"] + fields = ["name", "count"] class TagNestedSerializer(ModelSerializer):