8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-07 10:26:25 +00:00
re2o/machines/serializers.py

47 lines
1.3 KiB
Python
Raw Normal View History

2016-11-12 15:12:24 +00:00
#Augustin Lemesle
2016-07-18 21:22:59 +00:00
from rest_framework import serializers
2016-11-18 17:15:57 +00:00
from machines.models import Interface, IpType, Extension, IpList, MachineType, Alias
2016-07-18 21:22:59 +00:00
2016-11-16 18:30:48 +00:00
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)
2016-07-18 21:22:59 +00:00
class Meta:
model = Interface
2016-11-16 18:30:48 +00:00
fields = ('ipv4', 'mac_address', 'dns')
class ExtensionNameField(serializers.RelatedField):
def to_representation(self, value):
2016-11-16 18:30:48 +00:00
return value.name
2016-07-19 19:43:24 +00:00
2016-11-12 15:12:24 +00:00
class TypeSerializer(serializers.ModelSerializer):
2016-11-16 18:30:48 +00:00
extension = ExtensionNameField(read_only=True)
2016-11-12 15:12:24 +00:00
class Meta:
model = IpType
2016-11-16 18:30:48 +00:00
fields = ('type', 'extension', 'domaine_ip', 'domaine_range')
2016-07-18 21:22:59 +00:00
2016-11-18 17:15:57 +00:00
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)
2016-07-18 21:22:59 +00:00
2016-11-18 17:15:57 +00:00
class Meta:
model = Alias
fields = ('interface_parent', 'alias', 'extension')