mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
35 lines
948 B
Python
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')
|
|
|
|
|