netbox-acls/netbox_access_lists/api/nested_serializers.py
Ryan Merolle b0288037a2
Allow for ACL to VMs & Virtual Chassis on top of the current device association (#42)
* Associates hosts (devices, VMs, & virtual chassis) to each ACL
* Add a card to the object page for each of the above
* Update API & GraphQL
* Add a bulk delete button for ACL models
2022-07-21 10:30:52 -04:00

63 lines
1.9 KiB
Python

"""
Serializers control the translation of client data to and from Python objects,
while Django itself handles the database abstraction.
"""
from netbox.api.serializers import WritableNestedSerializer
from rest_framework import serializers
from ..models import AccessList, ACLExtendedRule, ACLStandardRule
__all__ = [
'NestedAccessListSerializer',
'NestedACLStandardRuleSerializer',
'NestedACLExtendedRuleSerializer'
]
class NestedAccessListSerializer(WritableNestedSerializer):
"""
Defines the nested serializer for the django AccessList model & associates it to a view.
"""
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_access_lists-api:accesslist-detail'
)
class Meta:
"""
Associates the django model ACLStandardRule & fields to the nested serializer.
"""
model = AccessList
fields = ('id', 'url', 'display', 'name')
class NestedACLStandardRuleSerializer(WritableNestedSerializer):
"""
Defines the nested serializer for the django ACLStandardRule model & associates it to a view.
"""
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_access_lists-api:aclstandardrule-detail'
)
class Meta:
"""
Associates the django model ACLStandardRule & fields to the nested serializer.
"""
model = ACLStandardRule
fields = ('id', 'url', 'display', 'index')
class NestedACLExtendedRuleSerializer(WritableNestedSerializer):
"""
Defines the nested serializer for the django ACLExtendedRule model & associates it to a view.
"""
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_access_lists-api:aclextendedrule-detail'
)
class Meta:
"""
Associates the django model ACLExtendedRule & fields to the nested serializer.
"""
model = ACLExtendedRule
fields = ('id', 'url', 'display', 'index')