Commit 7f4155e0 authored by Élie Bouttier's avatar Élie Bouttier

allocation: liens cliquables

parent 70b69d60
......@@ -193,6 +193,11 @@ class AllocationInline(admin.TabularInline):
show_change_link = True
ordering = ('-start',)
def resource_link(self, obj):
url = reverse('admin:services_ipresource_change', args=[obj.resource.pk])
return format_html('<a href="{}">{}</a>', url, str(obj.resource))
resource_link.short_description = 'IP'
def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.select_related('resource')
......@@ -237,6 +242,11 @@ class ServiceAllocationMixin:
raw_id_fields = ('resource',)
autocomplete_fields = ('service',)
def service_link(self, obj):
url = reverse('admin:services_service_change', args=[obj.service.pk])
return format_html('<a href="{}">{}</a>', url, str(obj.service))
service_link.short_description = 'Service'
def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.select_related('route')
......@@ -260,8 +270,8 @@ class NewServiceAllocationInline(ServiceAllocationMixin, NewAllocationMixin, All
class ActiveServiceAllocationInline(ServiceAllocationMixin, ActiveAllocationMixin, AllocationInline):
fields = ('id', 'service', 'resource', 'route', 'start', 'stop',)
readonly_fields = ('service', 'start', 'resource', 'stop',)
fields = ('id', 'service_link', 'resource_link', 'route', 'start', 'stop',)
readonly_fields = ('service_link', 'start', 'resource_link', 'stop',)
def stop(self, obj):
return format_html('<a href="{}" class="deletelink">Terminer</a>', reverse('admin:stop-allocation', kwargs={'resource': obj.resource.ip}))
......@@ -269,8 +279,8 @@ class ActiveServiceAllocationInline(ServiceAllocationMixin, ActiveAllocationMixi
class InactiveServiceAllocationInline(ServiceAllocationMixin, InactiveAllocationMixin, AllocationInline):
fields = ('id', 'service', 'resource', 'route', 'start', 'end')
readonly_fields = ('service', 'resource', 'route', 'start', 'end')
fields = ('id', 'service_link', 'resource_link', 'route', 'start', 'end')
readonly_fields = ('service_link', 'resource_link', 'route', 'start', 'end')
#class ActiveAntennaAllocationInline(AntennaAllocationMixin, ActiveAllocationMixin, AllocationInline):
......
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