From 87730a3ad2bf15327ad5cf09f008b72943c8c792 Mon Sep 17 00:00:00 2001 From: detraz Date: Mon, 18 Feb 2019 22:13:34 +0100 Subject: [PATCH] Fix room_name problem with building --- topologie/admin.py | 8 ++++++++ topologie/models.py | 9 +++++---- topologie/templates/topologie/aff_dormitory.html | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/topologie/admin.py b/topologie/admin.py index d2a25461..d6fa318e 100644 --- a/topologie/admin.py +++ b/topologie/admin.py @@ -39,6 +39,7 @@ from .models import ( AccessPoint, SwitchBay, Building, + Dormitory, PortProfile, ) @@ -87,6 +88,12 @@ class BuildingAdmin(VersionAdmin): """Administration d'un batiment""" pass + +class DormitoryAdmin(VersionAdmin): + """Administration d'une residence""" + pass + + class PortProfileAdmin(VersionAdmin): """Administration of a port profile""" pass @@ -99,5 +106,6 @@ admin.site.register(Stack, StackAdmin) admin.site.register(ModelSwitch, ModelSwitchAdmin) admin.site.register(ConstructorSwitch, ConstructorSwitchAdmin) admin.site.register(Building, BuildingAdmin) +admin.site.register(Dormitory, DormitoryAdmin) admin.site.register(SwitchBay, SwitchBayAdmin) admin.site.register(PortProfile, PortProfileAdmin) diff --git a/topologie/models.py b/topologie/models.py index 7e4f6499..dbb168f3 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -558,6 +558,10 @@ class Building(AclMixin, RevMixin, models.Model): """Returns all ap of the building""" return AccessPoint.all_ap_in(self) + @cached_property + def cached_name(self): + return self.__str__() + def __str__(self): if Dormitory.objects.count() > 1: return self.dormitory.name + " : " + self.name @@ -749,10 +753,7 @@ class Room(AclMixin, RevMixin, models.Model): unique_together = ('name', 'building') def __str__(self): - if Dormitory.objects.count() > 1: - return self.building.dormitory.name + " : " + self.building.name + self.name - else: - return self.building.name + self.name + return self.building.cached_name + self.name class PortProfile(AclMixin, RevMixin, models.Model): diff --git a/topologie/templates/topologie/aff_dormitory.html b/topologie/templates/topologie/aff_dormitory.html index 35808bd5..758e5e2c 100644 --- a/topologie/templates/topologie/aff_dormitory.html +++ b/topologie/templates/topologie/aff_dormitory.html @@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for dormitory in dormitory_list %} {{ dormitory.name }} - {% for building in dormitory.building_set.all %} {{ building }} {% endfor %} + {% for building in dormitory.building_set.all %} {{ building.name }} {% endfor %} {% can_edit dormitory %} {% include 'buttons/edit.html' with href='topologie:edit-dormitory' id=dormitory.id %}