Réparé erreur à la sauvegarde d'un nouveau poste
[auf_rh_dae.git] / project / dae / views.py
index 85549f4..e011ac8 100644 (file)
@@ -148,10 +148,16 @@ def poste(request, key=None):
         form = PosteForm(data, instance=poste, request=request)
         financementForm = FinancementForm(request.POST, instance=poste)
         piecesForm = PostePieceForm(request.POST, request.FILES, instance=poste)
-        comparaisons_formset = PosteComparaisonFormSet(
-            request.POST,
-            queryset=poste.comparaisons_internes.ma_region_ou_service(request.user)
-        )
+        if isinstance(poste, dae.Poste):
+            comparaisons_formset = PosteComparaisonFormSet(
+                request.POST,
+                queryset=poste.comparaisons_internes.ma_region_ou_service(request.user)
+            )
+        else:
+            comparaisons_formset = PosteComparaisonFormSet(
+                request.POST,
+                queryset=dae.PosteComparaison.objects.none()
+            )
         if form.is_valid() and piecesForm.is_valid() and financementForm.is_valid() and \
            comparaisons_formset.is_valid():
             poste = form.save()