diff --git a/osidb/serializer.py b/osidb/serializer.py index 895d7683e..0c1364b62 100644 --- a/osidb/serializer.py +++ b/osidb/serializer.py @@ -548,13 +548,21 @@ def get_parent_model(self, obj): class AlertMixinSerializer(serializers.ModelSerializer): """Serializes the alerts in models that implement AlertMixin.""" - alerts = AlertSerializer(many=True, read_only=True) + alerts = serializers.SerializerMethodField() class Meta: model = AlertMixin abstract = True fields = ["alerts"] + @extend_schema_field(AlertSerializer(many=True)) + def get_alerts(self, instance): + query_set = Alert.objects.filter( + object_id=instance.uuid, created_dt__gte=instance.last_validated_dt + ) + serializer = AlertSerializer(query_set, many=True, read_only=True) + return serializer.data + class AuditSerializer(serializers.ModelSerializer):