Commit 87730a3a authored by detraz's avatar detraz

Fix room_name problem with building

parent 8d799ed9
......@@ -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)
......@@ -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):
......
......@@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for dormitory in dormitory_list %}
<tr>
<td>{{ dormitory.name }}</td>
<td>{% for building in dormitory.building_set.all %} {{ building }} {% endfor %}</td>
<td>{% for building in dormitory.building_set.all %} {{ building.name }} {% endfor %}</td>
<td class="text-right">
{% can_edit dormitory %}
{% include 'buttons/edit.html' with href='topologie:edit-dormitory' id=dormitory.id %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment