8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 19:33:11 +00:00
re2o/machines/serializers.py
2016-11-16 19:30:48 +01:00

35 lines
948 B
Python

#Augustin Lemesle
from rest_framework import serializers
from machines.models import Interface, IpType, Extension, IpList, MachineType
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_reprsentation(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')