Skip to content

Commit

Permalink
Refactor AlertMixinSerializer to filter out outdated alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Dec 11, 2024
1 parent d556a98 commit 343840a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion osidb/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 343840a

Please sign in to comment.