From 59ad8e5970af9aaf11f00ecd9412fed7f6167ec7 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 20 Jul 2018 19:20:01 +0200 Subject: [PATCH] Fix #131 --- topologie/forms.py | 10 +--------- topologie/models.py | 6 +++++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/topologie/forms.py b/topologie/forms.py index ba37d395..86b5c541 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -89,15 +89,7 @@ class EditPortForm(FormRevMixin, ModelForm): self.fields['machine_interface'].queryset = ( Interface.objects.all().select_related('domain__extension') ) - self.fields['related'].queryset = ( - Port.objects.all() - .prefetch_related(Prefetch( - 'switch__interface_set', - queryset=(Interface.objects - .select_related('ipv4__ip_type__extension') - .select_related('domain__extension')) - )) - ) + self.fields['related'].queryset = Port.objects.all().prefetch_related('switch__machine_ptr__interface_set__domain__extension') class AddPortForm(FormRevMixin, ModelForm): diff --git a/topologie/models.py b/topologie/models.py index d22a0f75..00ed872e 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -359,8 +359,12 @@ class Switch(AclMixin, Machine): """Return dict ip6:subnet for all ipv6 of the switch""" return dict((str(interface.ipv6().first()), interface.type.ip_type.ip6_set_full_info) for interface in self.interface_set.all()) + @cached_property + def get_name(self): + return self.name or self.main_interface().domain.name + def __str__(self): - return str(self.main_interface()) + return str(self.get_name) class ModelSwitch(AclMixin, RevMixin, models.Model):