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-16 18:30:48 +00:00
|
|
|
from machines.models import Interface, IpType, Extension, IpList, MachineType
|
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_reprsentation(self,value):
|
|
|
|
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
|
|
|
|
|
|
|
|