Loading services/admin.py +13 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ from django.core.cache import cache from django.contrib.humanize.templatetags.humanize import naturaltime from django.contrib.contenttypes.models import ContentType from django.http import HttpResponseRedirect from django.core.exceptions import ValidationError from djgeojson.views import GeoJSONLayerView from urllib.parse import urlencode Loading Loading @@ -332,6 +333,17 @@ class ServicePortInline(PortInline): readonly_fields = ('switch', 'port', 'up',) ### Forms class ServiceForm(ModelForm): def clean_adhesion(self): if self.instance.adhesion.pk != self.cleaned_data['adhesion'].pk \ and not self.instance.is_active(): raise ValidationError('Il n’est pas possible de ré-affecter à un autre adhérent un service inactif (i.e. sans allocations actives).') return self.cleaned_data['adhesion'] ### ModelAdmin class ServiceAdmin(admin.ModelAdmin): Loading @@ -346,6 +358,7 @@ class ServiceAdmin(admin.ModelAdmin): fields = ('adhesion', 'service_type', 'label', 'notes', 'loan_equipment', 'get_contribution_link', 'is_active',) readonly_fields = ('get_contribution_link', 'is_active',) raw_id_fields = ('adhesion',) form = ServiceForm def save_model(self, request, srv, form, change): if 'adhesion' in form.changed_data: Loading Loading
services/admin.py +13 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ from django.core.cache import cache from django.contrib.humanize.templatetags.humanize import naturaltime from django.contrib.contenttypes.models import ContentType from django.http import HttpResponseRedirect from django.core.exceptions import ValidationError from djgeojson.views import GeoJSONLayerView from urllib.parse import urlencode Loading Loading @@ -332,6 +333,17 @@ class ServicePortInline(PortInline): readonly_fields = ('switch', 'port', 'up',) ### Forms class ServiceForm(ModelForm): def clean_adhesion(self): if self.instance.adhesion.pk != self.cleaned_data['adhesion'].pk \ and not self.instance.is_active(): raise ValidationError('Il n’est pas possible de ré-affecter à un autre adhérent un service inactif (i.e. sans allocations actives).') return self.cleaned_data['adhesion'] ### ModelAdmin class ServiceAdmin(admin.ModelAdmin): Loading @@ -346,6 +358,7 @@ class ServiceAdmin(admin.ModelAdmin): fields = ('adhesion', 'service_type', 'label', 'notes', 'loan_equipment', 'get_contribution_link', 'is_active',) readonly_fields = ('get_contribution_link', 'is_active',) raw_id_fields = ('adhesion',) form = ServiceForm def save_model(self, request, srv, form, change): if 'adhesion' in form.changed_data: Loading