From afa05afcc0a058aa87db82070c292ad6a67ea789 Mon Sep 17 00:00:00 2001 From: Patrick Mayr Date: Mon, 18 Sep 2023 11:39:34 +0000 Subject: [PATCH] fix if there is no instance, it throws an error --- fet2020/finance/forms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fet2020/finance/forms.py b/fet2020/finance/forms.py index c146b333..aea2d6d2 100644 --- a/fet2020/finance/forms.py +++ b/fet2020/finance/forms.py @@ -291,7 +291,8 @@ class ResolutionAdminForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # to get the self.fields set - bills = Bill.objects.filter(resolution=kwargs["instance"]) + resolution = kwargs.get("instance", None) + bills = Bill.objects.filter(resolution=resolution) total = 0 for elem in bills: total += elem.amount @@ -322,7 +323,8 @@ class WirefAdminForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # to get the self.fields set - bills = Bill.objects.filter(wiref=kwargs["instance"]) + wiref = kwargs.get("instance", None) + bills = Bill.objects.filter(wiref=wiref) total = 0 for elem in bills: total += elem.amount