8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 15:33:45 +00:00
This commit is contained in:
Gabriel Detraz 2018-07-20 19:20:01 +02:00
parent fc612f47dc
commit 59ad8e5970
2 changed files with 6 additions and 10 deletions

View file

@ -89,15 +89,7 @@ class EditPortForm(FormRevMixin, ModelForm):
self.fields['machine_interface'].queryset = ( self.fields['machine_interface'].queryset = (
Interface.objects.all().select_related('domain__extension') Interface.objects.all().select_related('domain__extension')
) )
self.fields['related'].queryset = ( self.fields['related'].queryset = Port.objects.all().prefetch_related('switch__machine_ptr__interface_set__domain__extension')
Port.objects.all()
.prefetch_related(Prefetch(
'switch__interface_set',
queryset=(Interface.objects
.select_related('ipv4__ip_type__extension')
.select_related('domain__extension'))
))
)
class AddPortForm(FormRevMixin, ModelForm): class AddPortForm(FormRevMixin, ModelForm):

View file

@ -359,8 +359,12 @@ class Switch(AclMixin, Machine):
"""Return dict ip6:subnet for all ipv6 of the switch""" """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()) 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): def __str__(self):
return str(self.main_interface()) return str(self.get_name)
class ModelSwitch(AclMixin, RevMixin, models.Model): class ModelSwitch(AclMixin, RevMixin, models.Model):