dfdf
This commit is contained in:
@@ -506,7 +506,12 @@ class ImagesViewSet(SiteSectorModelViewSet):
|
|||||||
|
|
||||||
@action(detail=False, methods=['post'], url_path='bulk_update', url_name='bulk_update')
|
@action(detail=False, methods=['post'], url_path='bulk_update', url_name='bulk_update')
|
||||||
def bulk_update(self, request):
|
def bulk_update(self, request):
|
||||||
"""Bulk update image status by content_id or image IDs"""
|
"""Bulk update image status by content_id or image IDs
|
||||||
|
Updates all images for a content record (featured + 1-6 in-article images)
|
||||||
|
"""
|
||||||
|
from django.db.models import Q
|
||||||
|
from .models import Content
|
||||||
|
|
||||||
content_id = request.data.get('content_id')
|
content_id = request.data.get('content_id')
|
||||||
image_ids = request.data.get('ids', [])
|
image_ids = request.data.get('ids', [])
|
||||||
status_value = request.data.get('status')
|
status_value = request.data.get('status')
|
||||||
@@ -518,7 +523,17 @@ class ImagesViewSet(SiteSectorModelViewSet):
|
|||||||
|
|
||||||
# Update by content_id if provided, otherwise by image IDs
|
# Update by content_id if provided, otherwise by image IDs
|
||||||
if content_id:
|
if content_id:
|
||||||
updated_count = queryset.filter(content_id=content_id).update(status=status_value)
|
try:
|
||||||
|
# Get the content object to also update images linked via task
|
||||||
|
content = Content.objects.get(id=content_id)
|
||||||
|
|
||||||
|
# Update images linked directly to content OR via task (same logic as content_images endpoint)
|
||||||
|
# This ensures we update all images: featured + 1-6 in-article images
|
||||||
|
updated_count = queryset.filter(
|
||||||
|
Q(content=content) | Q(task=content.task)
|
||||||
|
).update(status=status_value)
|
||||||
|
except Content.DoesNotExist:
|
||||||
|
return Response({'error': 'Content not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
elif image_ids:
|
elif image_ids:
|
||||||
updated_count = queryset.filter(id__in=image_ids).update(status=status_value)
|
updated_count = queryset.filter(id__in=image_ids).update(status=status_value)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user