mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 21:18:16 -06:00
14438 add generic relation so delete will show event rule
This commit is contained in:
parent
63d3ce6e77
commit
bc596340c3
@ -84,7 +84,10 @@ class EventRuleSerializer(NetBoxModelSerializer):
|
|||||||
if instance.action_type == EventRuleActionChoices.SCRIPT:
|
if instance.action_type == EventRuleActionChoices.SCRIPT:
|
||||||
script = instance.action_object
|
script = instance.action_object
|
||||||
script_name = script.name
|
script_name = script.name
|
||||||
return NestedScriptSerializer(script.python_class(), context=context).data
|
if script.python_class:
|
||||||
|
return NestedScriptSerializer(script.python_class(), context=context).data
|
||||||
|
else:
|
||||||
|
return NestedScriptSerializer(None, context=context).data
|
||||||
else:
|
else:
|
||||||
serializer = get_serializer_for_model(
|
serializer = get_serializer_for_model(
|
||||||
model=instance.action_object_type.model_class(),
|
model=instance.action_object_type.model_class(),
|
||||||
|
@ -2,6 +2,7 @@ import inspect
|
|||||||
import logging
|
import logging
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
|
|
||||||
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@ -35,6 +36,11 @@ class Script(EventRulesMixin, JobsMixin, models.Model):
|
|||||||
is_valid = models.BooleanField(
|
is_valid = models.BooleanField(
|
||||||
default=True
|
default=True
|
||||||
)
|
)
|
||||||
|
events = GenericRelation(
|
||||||
|
'extras.EventRule',
|
||||||
|
content_type_field='action_object_type',
|
||||||
|
object_id_field='action_object_id'
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
Loading…
Reference in New Issue
Block a user