From 30140de2ae11b05e161271c7d523c72dc32ea1fa Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 18 Apr 2018 18:11:36 +0200 Subject: [PATCH] Des methodes raccourci pour mon gentil grizzly --- topologie/models.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/topologie/models.py b/topologie/models.py index 23b72b75..354c975d 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -103,6 +103,23 @@ class AccessPoint(AclMixin, Machine): ("view_accesspoint", "Peut voir une borne"), ) + def switch(self): + """Return the switch where this is plugged""" + return Switch.objects.filter( + ports__machine_interface__machine=self + ) + + def building(self): + """Return the building of the AP (building of the switchs connected to...)""" + return Building.objects.filter( + switchbay__switch=self.switch() + ) + + @classmethod + def all_ap_in(cls, building_instance): + """Get a building as argument, returns all ap of a building""" + return cls.objects.filter(interface__port__switch__switchbay__building=building_instance) + def __str__(self): return str(self.interface_set.first())