mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
#Augustin Lemesle
|
|
|
|
from rest_framework import serializers
|
|
from machines.models import Interface, IpType, Extension, IpList, MachineType, Alias
|
|
|
|
class IpTypeField(serializers.RelatedField):
|
|
def to_representation(self, value):
|
|
return value.type
|
|
|
|
class IpListSerializer(serializers.ModelSerializer):
|
|
ip_type = IpTypeField(read_only=True)
|
|
|
|
class Meta:
|
|
model = IpList
|
|
fields = ('ipv4', 'ip_type')
|
|
|
|
class InterfaceSerializer(serializers.ModelSerializer):
|
|
ipv4 = IpListSerializer(read_only=True)
|
|
|
|
class Meta:
|
|
model = Interface
|
|
fields = ('ipv4', 'mac_address', 'dns')
|
|
|
|
class ExtensionNameField(serializers.RelatedField):
|
|
def to_representation(self, value):
|
|
return value.name
|
|
|
|
class TypeSerializer(serializers.ModelSerializer):
|
|
extension = ExtensionNameField(read_only=True)
|
|
|
|
class Meta:
|
|
model = IpType
|
|
fields = ('type', 'extension', 'domaine_ip', 'domaine_range')
|
|
|
|
class InterfaceDNS_ExtensionSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Interface
|
|
fields = ('ipv4', 'dns')
|
|
|
|
class AliasSerializer(serializers.ModelSerializer):
|
|
interface_parent = InterfaceDNS_ExtensionSerializer(read_only=True)
|
|
extension = ExtensionNameField(read_only=True)
|
|
|
|
class Meta:
|
|
model = Alias
|
|
fields = ('interface_parent', 'alias', 'extension')
|