Browse Source

fix regression

Élie Bouttier 6 years ago
parent
commit
cccc8acf52
1 changed files with 3 additions and 2 deletions
  1. 3 2
      services/admin.py

+ 3 - 2
services/admin.py

@@ -338,7 +338,8 @@ class ServicePortInline(PortInline):
 
 class ServiceForm(ModelForm):
     def clean_adhesion(self):
-        if self.instance.adhesion.pk != self.cleaned_data['adhesion'].pk \
+        if hasattr(self.instance, 'adhesion') \
+                and 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']
@@ -361,7 +362,7 @@ class ServiceAdmin(admin.ModelAdmin):
     form = ServiceForm
 
     def save_model(self, request, srv, form, change):
-        if 'adhesion' in form.changed_data:
+        if srv.pk and 'adhesion' in form.changed_data:
             with transaction.atomic():
                 old_srv = Service.objects.get(pk=srv.pk)
                 adhesion = srv.adhesion