14132 nested serializer

This commit is contained in:
Arthur 2023-11-29 12:05:42 -08:00
parent 57d454f8b4
commit 6d28cac99f
2 changed files with 9 additions and 1 deletions

View File

@ -15,6 +15,7 @@ __all__ = [
'NestedImageAttachmentSerializer', 'NestedImageAttachmentSerializer',
'NestedJournalEntrySerializer', 'NestedJournalEntrySerializer',
'NestedSavedFilterSerializer', 'NestedSavedFilterSerializer',
'NestedScriptModuleSerializer',
'NestedTagSerializer', # Defined in netbox.api.serializers 'NestedTagSerializer', # Defined in netbox.api.serializers
'NestedWebhookSerializer', 'NestedWebhookSerializer',
] ]
@ -113,3 +114,10 @@ class NestedJournalEntrySerializer(WritableNestedSerializer):
class Meta: class Meta:
model = models.JournalEntry model = models.JournalEntry
fields = ['id', 'url', 'display', 'created'] fields = ['id', 'url', 'display', 'created']
class NestedScriptModuleSerializer(serializers.Serializer):
fields = ['id', ]
def get_display(self, obj):
return f'{obj.name} ({obj.module})'

View File

@ -332,7 +332,7 @@ class EventRuleForm(NetBoxModelForm):
self.cleaned_data['action_object_id'] = action_choice.id self.cleaned_data['action_object_id'] = action_choice.id
elif self.cleaned_data.get('action_type') == EventRuleActionChoices.SCRIPT: elif self.cleaned_data.get('action_type') == EventRuleActionChoices.SCRIPT:
script = ScriptModule.objects.get(pk=action_choice.split(":")[0]) script = ScriptModule.objects.get(pk=action_choice.split(":")[0])
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(script) self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(script, for_concrete_model=False)
self.cleaned_data['action_object_id'] = script.id self.cleaned_data['action_object_id'] = script.id
self.cleaned_data['action_parameters'] = {'script_choice': action_choice} self.cleaned_data['action_parameters'] = {'script_choice': action_choice}