From 9828c994b865327d6868963341ae7574212aefb7 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 12 Mar 2024 11:21:56 +0100
Subject: [PATCH] add autocomplete subsidy field to attachment form

---
 scipost_django/finances/forms.py                    | 13 +++++++++++++
 .../templates/finances/subsidyattachment_form.html  |  5 +++++
 2 files changed, 18 insertions(+)

diff --git a/scipost_django/finances/forms.py b/scipost_django/finances/forms.py
index c642baf03..bd3d71021 100644
--- a/scipost_django/finances/forms.py
+++ b/scipost_django/finances/forms.py
@@ -301,6 +301,19 @@ class SubsidyAttachmentForm(forms.ModelForm):
             "date": forms.DateInput(attrs={"type": "date"}),
         }
 
+    subsidy = forms.ModelChoiceField(
+        queryset=Subsidy.objects.all(),
+        widget=autocomplete.ModelSelect2(
+            url=reverse_lazy("finances:subsidy_autocomplete"),
+            attrs={
+                "data-html": True,
+                "style": "width: 100%",
+            },
+        ),
+        help_text=("Start typing, and select from the popup."),
+        required=False,
+    )
+
     def clean_attachment(self):
         attachment = self.cleaned_data["attachment"]
 
diff --git a/scipost_django/finances/templates/finances/subsidyattachment_form.html b/scipost_django/finances/templates/finances/subsidyattachment_form.html
index b8b24a267..3fdf09fac 100644
--- a/scipost_django/finances/templates/finances/subsidyattachment_form.html
+++ b/scipost_django/finances/templates/finances/subsidyattachment_form.html
@@ -83,3 +83,8 @@
     </div>
   </div>
 {% endblock content %}
+
+{% block footer_script %}
+  {{ block.super }}
+  {{ form.media }}
+{% endblock footer_script %}
-- 
GitLab