mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 16:11:08 -05:00
fix location add
This commit is contained in:
@@ -57,7 +57,7 @@ def upload_photo(request):
|
||||
|
||||
# Get the object instance
|
||||
try:
|
||||
obj = content_type.get_object_for_this_type(id=object_id)
|
||||
obj = content_type.get_object_for_this_type(pk=object_id)
|
||||
except Exception as e:
|
||||
return JsonResponse(
|
||||
{
|
||||
@@ -82,17 +82,17 @@ def upload_photo(request):
|
||||
photo = Photo.objects.create(
|
||||
image=request.FILES["image"],
|
||||
content_type=content_type,
|
||||
object_id=obj.id,
|
||||
object_id=obj.pk,
|
||||
uploaded_by=request.user, # Add the user who uploaded the photo
|
||||
is_primary=not Photo.objects.filter(
|
||||
content_type=content_type, object_id=obj.id
|
||||
content_type=content_type, object_id=obj.pk
|
||||
).exists(),
|
||||
is_approved=is_approved # Auto-approve if the user is a moderator, admin, or superuser
|
||||
)
|
||||
|
||||
return JsonResponse(
|
||||
{
|
||||
"id": photo.id,
|
||||
"id": photo.pk,
|
||||
"url": photo.image.url,
|
||||
"caption": photo.caption,
|
||||
"is_primary": photo.is_primary,
|
||||
@@ -113,7 +113,7 @@ def upload_photo(request):
|
||||
def set_primary_photo(request, photo_id):
|
||||
"""Set a photo as primary"""
|
||||
try:
|
||||
photo = get_object_or_404(Photo, id=photo_id)
|
||||
photo = get_object_or_404(Photo, pk=photo_id)
|
||||
|
||||
# Check if user has permission to edit photos
|
||||
if not request.user.has_perm("media.change_photo"):
|
||||
@@ -137,7 +137,7 @@ def set_primary_photo(request, photo_id):
|
||||
def update_caption(request, photo_id):
|
||||
"""Update a photo's caption"""
|
||||
try:
|
||||
photo = get_object_or_404(Photo, id=photo_id)
|
||||
photo = get_object_or_404(Photo, pk=photo_id)
|
||||
|
||||
# Check if user has permission to edit photos
|
||||
if not request.user.has_perm("media.change_photo"):
|
||||
@@ -150,7 +150,7 @@ def update_caption(request, photo_id):
|
||||
photo.caption = data.get("caption", "")
|
||||
photo.save()
|
||||
|
||||
return JsonResponse({"id": photo.id, "caption": photo.caption})
|
||||
return JsonResponse({"id": photo.pk, "caption": photo.caption})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in update_caption: {str(e)}", exc_info=True)
|
||||
@@ -162,7 +162,7 @@ def update_caption(request, photo_id):
|
||||
def delete_photo(request, photo_id):
|
||||
"""Delete a photo"""
|
||||
try:
|
||||
photo = get_object_or_404(Photo, id=photo_id)
|
||||
photo = get_object_or_404(Photo, pk=photo_id)
|
||||
|
||||
# Check if user has permission to delete photos
|
||||
if not request.user.has_perm("media.delete_photo"):
|
||||
|
||||
Reference in New Issue
Block a user