From aed021821a45bc8b82ebe08d930a1097839a33a4 Mon Sep 17 00:00:00 2001 From: Dalahro Date: Fri, 18 Nov 2016 20:16:40 +0100 Subject: [PATCH] Pour mettre l'extension et bien se faire chier, plus kikimeter --- machines/serializers.py | 8 +------- machines/views.py | 12 +++++++----- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/machines/serializers.py b/machines/serializers.py index 40c38a72..e9fdde29 100644 --- a/machines/serializers.py +++ b/machines/serializers.py @@ -22,7 +22,7 @@ class InterfaceSerializer(serializers.ModelSerializer): fields = ('ipv4', 'mac_address', 'dns') class ExtensionNameField(serializers.RelatedField): - def to_reprsentation(self, value): + def to_representation(self, value): return value.name class TypeSerializer(serializers.ModelSerializer): @@ -32,13 +32,7 @@ class TypeSerializer(serializers.ModelSerializer): model = IpType fields = ('type', 'extension', 'domaine_ip', 'domaine_range') -class IpList_ExtensionField(serializers.RelatedField): - def to_representation(self, value): - return value.ipv4.ip_type.extension.name - class InterfaceDNS_ExtensionSerializer(serializers.ModelSerializer): - ipv4 = IpList_ExtensionField(read_only=True) - class Meta: model = Interface fields = ('ipv4', 'dns') diff --git a/machines/views.py b/machines/views.py index 8e66c1d3..d7abcada 100644 --- a/machines/views.py +++ b/machines/views.py @@ -469,12 +469,14 @@ def interface_list(request): @login_required @permission_required('serveur') def alias(request): - aliass = Alias.objects.all() - alias = [] - for a in aliass: - if a.interface_parent.ipv4: - alias.append(a) + alias = Alias.objects.all() seria = AliasSerializer(alias, many=True) + for d in seria.data: + if d["interface_parent"]["ipv4"]: + id = d["interface_parent"]["ipv4"] + ip_list = IpList.objects.get(pk=id) + d["interface_parent"]["extension"] = ip_list.ip_type.extension.name + d["interface_parent"].pop("ipv4") return JSONResponse(seria.data) @csrf_exempt