Add action_object to EventRule serializer

This commit is contained in:
Jeremy Stretch 2023-11-29 09:52:22 -05:00
parent afc1e789d2
commit bce43eabc9

View File

@ -71,15 +71,25 @@ class EventRuleSerializer(NetBoxModelSerializer):
action_object_type = ContentTypeField(
queryset=ContentType.objects.with_feature('event_rules'),
)
action_object = serializers.SerializerMethodField(read_only=True)
class Meta:
model = EventRule
fields = [
'id', 'url', 'display', 'content_types', 'name', 'type_create', 'type_update', 'type_delete',
'type_job_start', 'type_job_end', 'enabled', 'conditions', 'action_type', 'action_object_type',
'action_object_id', 'custom_fields', 'tags', 'created', 'last_updated',
'action_object_id', 'action_object', 'custom_fields', 'tags', 'created', 'last_updated',
]
@extend_schema_field(OpenApiTypes.OBJECT)
def get_action_object(self, instance):
serializer = get_serializer_for_model(
model=instance.action_object_type.model_class(),
prefix=NESTED_SERIALIZER_PREFIX
)
context = {'request': self.context['request']}
return serializer(instance.action_object, context=context).data
#
# Webhooks