aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/views.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-08-01 16:17:23 +0100
committerMatthew Lemon <y@yulqen.org>2024-08-01 16:17:23 +0100
commitbad2be31054ff5277b97230b5157edf6a8dd06cc (patch)
treedc9072a73d586fb00671f742a2e9054fec37f230 /pyblackbird_cc/resources/views.py
parent5f37a5839ff00f4f85c5e63e4dcb8246204c9386 (diff)
Fix bug where new subcategories were being created on selection
Diffstat (limited to 'pyblackbird_cc/resources/views.py')
-rw-r--r--pyblackbird_cc/resources/views.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py
index 4381267..9d85bfa 100644
--- a/pyblackbird_cc/resources/views.py
+++ b/pyblackbird_cc/resources/views.py
@@ -100,8 +100,8 @@ def _extract_metadata_from_resource(resource_obj) -> ResourceInfo | None:
for f in resource_obj.thumbnail_filenames
]
try:
- if resource_obj.additional_resource_category:
- arc_name = resource_obj.additional_resource_category.name
+ if resource_obj.subcategories:
+ arc_name = resource_obj.subcategories.name
else:
arc_name = None
return ResourceInfo(
@@ -253,10 +253,11 @@ def create_resource(request):
age_range = form.cleaned_data["age_range"]
curriculum = form.cleaned_data["curriculum"]
main_resource_category = form.cleaned_data["main_resource_category"]
- additional_resource_category = form.cleaned_data["additional_resource_category"]
+ subcategories = form.cleaned_data["subcategories"]
feature_slot = form.cleaned_data["feature_slot"]
- additional_resource_category_objs = [ResourceSubcategory.objects.create(name=x) for x in additional_resource_category]
+ # We use get here because we know these categories exist
+ subcategories_objs = [ResourceSubcategory.objects.get(name=x) for x in subcategories]
try:
with transaction.atomic():
@@ -271,7 +272,7 @@ def create_resource(request):
feature_slot=feature_slot,
)
resource.save()
- resource.additional_resource_category.set(additional_resource_category_objs)
+ resource.subcategories.set(subcategories_objs)
metadata_generator = create_metadata(pdf_files)
snapshotted_pages = []
@@ -346,8 +347,8 @@ def resource_detail(request, resource_id):
"resource_type": resource_obj.resource_type.name,
"main_resource_category": resource_obj.main_resource_category.name,
"additional_resource_category": (
- resource_obj.additional_resource_category.name
- if resource_obj.additional_resource_category
+ resource_obj.subcategories.name
+ if resource_obj.subcategories
else None
),
"age_range": resource_obj.age_range,