aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-07-29 15:18:29 +0100
committerMatthew Lemon <y@yulqen.org>2024-07-29 15:18:29 +0100
commited05d376b79bdac7e3809193025ac6da7261113e (patch)
tree3c325a0d674b763e077679e311ac76ef94dcfcc1 /pyblackbird_cc/resources
parentb059587e61cef2d20fb2614aea21685ff4c1b9ce (diff)
wip: creating a multiple choice field for additional categories
Diffstat (limited to 'pyblackbird_cc/resources')
-rw-r--r--pyblackbird_cc/resources/forms.py13
-rw-r--r--pyblackbird_cc/resources/models.py3
2 files changed, 12 insertions, 4 deletions
diff --git a/pyblackbird_cc/resources/forms.py b/pyblackbird_cc/resources/forms.py
index 35c5034..1b82ab7 100644
--- a/pyblackbird_cc/resources/forms.py
+++ b/pyblackbird_cc/resources/forms.py
@@ -1,4 +1,5 @@
import logging
+from typing import List, Tuple
import magic
from crispy_forms.helper import FormHelper
@@ -18,6 +19,14 @@ ALLOWED_THUMBNAILS = 5
ALLOWED_PDFS = 20
+def _create_choices_tuple() -> List[Tuple[str, str]]:
+ qs_lst = list(ResourceCategory.objects.values_list('name', flat=True))
+ res = []
+ for x in qs_lst:
+ res.append((x, x))
+ return res
+
+
class ResourceCreateForm(forms.Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -75,8 +84,8 @@ class ResourceCreateForm(forms.Form):
"searches. It's a good idea to limit the number of subjects you select "
"to one or two to make your resource easier to find.",
)
- additional_resource_category = forms.ModelChoiceField(
- queryset=ResourceCategory.objects.all(),
+ additional_resource_category = forms.MultipleChoiceField(
+ choices=_create_choices_tuple(),
required=False,
)
pdf_files = forms.FileField(
diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py
index 6b0a9b0..d302ae6 100644
--- a/pyblackbird_cc/resources/models.py
+++ b/pyblackbird_cc/resources/models.py
@@ -45,9 +45,8 @@ class Resource(models.Model):
null=False,
related_name="main_resource_category",
)
- additional_resource_category = models.ForeignKey(
+ additional_resource_category = models.ManyToManyField(
"ResourceCategory",
- on_delete=models.CASCADE,
null=True,
blank=True,
related_name="additional_resource_category",