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 %}