mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-23 03:31:09 -05:00
initial geodjango implementation
This commit is contained in:
Binary file not shown.
18
media/migrations/0006_photo_is_approved.py
Normal file
18
media/migrations/0006_photo_is_approved.py
Normal 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),
|
||||
),
|
||||
]
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user