aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/views.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/views.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/views.py')
-rw-r--r--pyblackbird_cc/resources/views.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py
index db236f0..4381267 100644
--- a/pyblackbird_cc/resources/views.py
+++ b/pyblackbird_cc/resources/views.py
@@ -19,7 +19,7 @@ from django.shortcuts import render
from . import services
from .forms import ResourceCreateForm
from .forms import ResourceUpdateMetadataForm
-from .models import PDFPageSnapshot
+from .models import PDFPageSnapshot, ResourceSubcategory
from .models import PDFResource
from .models import Resource
@@ -256,9 +256,11 @@ def create_resource(request):
additional_resource_category = form.cleaned_data["additional_resource_category"]
feature_slot = form.cleaned_data["feature_slot"]
+ additional_resource_category_objs = [ResourceSubcategory.objects.create(name=x) for x in additional_resource_category]
+
try:
with transaction.atomic():
- resource = Resource.objects.create(
+ resource = Resource(
name=name,
description=description,
card_description=card_description,
@@ -266,9 +268,10 @@ def create_resource(request):
age_range=age_range,
curriculum=curriculum,
main_resource_category=main_resource_category,
- additional_resource_category=additional_resource_category,
feature_slot=feature_slot,
)
+ resource.save()
+ resource.additional_resource_category.set(additional_resource_category_objs)
metadata_generator = create_metadata(pdf_files)
snapshotted_pages = []
@@ -290,7 +293,6 @@ def create_resource(request):
snapshotted_pages.append(snapshot_images)
resource.thumbnail_filenames = [f.name for f in thumbnail_files]
- resource.save()
# Reset the file pointers for pdf_files
for pdf_file in pdf_files: