initial geodjango implementation

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

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2024-11-05 03:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("media", "0005_alter_photo_image"),
]
operations = [
migrations.AddField(
model_name="photo",
name="is_approved",
field=models.BooleanField(default=False),
),
]

View File

@@ -53,6 +53,7 @@ class Photo(models.Model):
caption = models.CharField(max_length=255, blank=True)
alt_text = models.CharField(max_length=255, blank=True)
is_primary = models.BooleanField(default=False)
is_approved = models.BooleanField(default=False) # New field for approval status
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
uploaded_by = models.ForeignKey(

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,
}
)