From 97d3db5f9bdcf4534efff2ca16ef16dc9435633d Mon Sep 17 00:00:00 2001 From: chirac Date: Sun, 24 Jun 2018 15:59:04 +0200 Subject: [PATCH] =?UTF-8?q?Fonctions=20machines=20pour=20r=C3=A9cup=20les?= =?UTF-8?q?=20tld=20en=20string=20,=20mise=20en=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/models.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/machines/models.py b/machines/models.py index 9872bbb3..57a917d0 100644 --- a/machines/models.py +++ b/machines/models.py @@ -33,6 +33,7 @@ from itertools import chain from netaddr import mac_bare, EUI, IPSet, IPRange, IPNetwork, IPAddress from django.db import models +from django.db.models import Q from django.db.models.signals import post_save, post_delete from django.dispatch import receiver from django.forms import ValidationError @@ -192,8 +193,24 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model): @cached_property def short_name(self): + """Par defaut, renvoie le nom de la première interface + de cette machine""" return str(self.interface_set.first().domain.name) + @cached_property + def all_short_names(self): + """Renvoie de manière unique, le nom des interfaces de cette + machine""" + return Domain.objects.filter( + interface_parent__machine=self + ).values_list('name', flat=True).distinct() + + @cached_property + def all_complete_names(self): + """Renvoie tous les tls complets de la machine""" + return [str(domain) for domain in Domain.objects.filter( + Q(cname__interface_parent__machine=self) | Q(interface_parent__machine=self) + )] def __init__(self, *args, **kwargs): super(Machine, self).__init__(*args, **kwargs)