fix if there is no instance, it throws an error

This commit is contained in:
2023-09-18 11:39:34 +00:00
parent 76eba4392e
commit afa05afcc0

View File

@@ -291,7 +291,8 @@ class ResolutionAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # to get the self.fields set 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 total = 0
for elem in bills: for elem in bills:
total += elem.amount total += elem.amount
@@ -322,7 +323,8 @@ class WirefAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # to get the self.fields set 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 total = 0
for elem in bills: for elem in bills:
total += elem.amount total += elem.amount