mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
14852 delete event-rule when delete script
This commit is contained in:
@ -89,8 +89,11 @@ class EventRuleSerializer(NetBoxModelSerializer):
|
||||
# We need to manually instantiate the serializer for scripts
|
||||
if instance.action_type == EventRuleActionChoices.SCRIPT:
|
||||
script_name = instance.action_parameters['script_name']
|
||||
if script_name in instance.action_object.scripts:
|
||||
script = instance.action_object.scripts[script_name]()
|
||||
return NestedScriptSerializer(script, context=context).data
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
serializer = get_serializer_for_model(
|
||||
model=instance.action_object_type.model_class(),
|
||||
|
@ -2,6 +2,7 @@ import inspect
|
||||
import logging
|
||||
from functools import cached_property
|
||||
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -41,6 +42,13 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
||||
"""
|
||||
objects = ScriptModuleManager()
|
||||
|
||||
event_rules = GenericRelation(
|
||||
to='extras.EventRule',
|
||||
content_type_field='action_object_type',
|
||||
object_id_field='action_object_id',
|
||||
for_concrete_model=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
verbose_name = _('script module')
|
||||
|
Reference in New Issue
Block a user