initial geodjango implementation

This commit is contained in:
pacnpal
2024-11-05 04:10:47 +00:00
parent c66fc2b6e3
commit 491be57ab2
22 changed files with 768 additions and 229 deletions

View File

@@ -75,16 +75,19 @@ def upload_photo(request):
{"error": "You do not have permission to upload photos"}, status=403
)
# Determine if the photo should be auto-approved
is_approved = request.user.is_superuser or request.user.is_staff or request.user.groups.filter(name='Moderators').exists()
# Create the photo
photo = Photo.objects.create(
image=request.FILES["image"],
content_type=content_type,
object_id=obj.id,
uploaded_by=request.user, # Add the user who uploaded the photo
# Set as primary if it's the first photo
is_primary=not Photo.objects.filter(
content_type=content_type, object_id=obj.id
).exists(),
is_approved=is_approved # Auto-approve if the user is a moderator, admin, or superuser
)
return JsonResponse(
@@ -93,6 +96,7 @@ def upload_photo(request):
"url": photo.image.url,
"caption": photo.caption,
"is_primary": photo.is_primary,
"is_approved": photo.is_approved,
}
)