aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/forms.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-07-29 17:06:29 +0100
committerMatthew Lemon <y@yulqen.org>2024-07-29 17:06:29 +0100
commitb3d46f2ddbd7312e731e8a05e09a8b547439b2ff (patch)
tree70fc0e4487dee1ee2f2febf083f35a7a0a38721e /pyblackbird_cc/resources/forms.py
parent914fb4dd4ab8b7e37c67de01d6a42802999553c1 (diff)
wip: Adds a new model for additional categories
- Adds new ResourceSubcategory - Uses this for choices= in the Resource form (create) - Adds this new model to the admin Doesn't validate in the edit form yet,
Diffstat (limited to 'pyblackbird_cc/resources/forms.py')
-rw-r--r--pyblackbird_cc/resources/forms.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py
index dbc6df5..efe1ccb 100644
--- a/pyblackbird_cc/resources/forms.py
+++ b/pyblackbird_cc/resources/forms.py
@@ -6,7 +6,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from django import forms
-from pyblackbird_cc.resources.models import Resource
+from pyblackbird_cc.resources.models import Resource, ResourceSubcategory
from pyblackbird_cc.resources.models import ResourceCategory
from pyblackbird_cc.resources.models import ResourceType
from .models import AGE_RANGE_CHOICES
@@ -19,7 +19,7 @@ ALLOWED_PDFS = 20
def _create_choices_tuple() -> List[Tuple[str, str]]:
- qs_lst = list(ResourceCategory.objects.values_list('name', flat=True))
+ qs_lst = list(ResourceSubcategory.objects.values_list('name', flat=True))
res = []
for x in qs_lst:
res.append((x, x))
@@ -31,6 +31,7 @@ class ResourceCreateForm(forms.Form):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.add_input(Submit("submit", "Submit"))
+ self.fields['additional_resource_category'].choices = _create_choices_tuple()
error_css_class = "error"
required_css_class = "required"
@@ -84,9 +85,9 @@ class ResourceCreateForm(forms.Form):
"to one or two to make your resource easier to find.",
)
additional_resource_category = forms.MultipleChoiceField(
- choices=_create_choices_tuple(),
required=False,
)
+
pdf_files = forms.FileField(
widget=forms.TextInput(
attrs={
@@ -159,6 +160,7 @@ class ResourceUpdateMetadataForm(forms.ModelForm):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.add_input(Submit("submit", "Submit"))
+ self.fields['additional_resource_category'].choices = _create_choices_tuple()
error_css_class = "error"
required_css_class = "required"