feat: Implement initial schema and add various API, service, and management command enhancements across the application.

This commit is contained in:
pacnpal
2026-01-01 15:13:01 -05:00
parent c95f99ca10
commit b243b17af7
413 changed files with 11164 additions and 17433 deletions

View File

@@ -17,16 +17,15 @@ def update_average_rating(sender, instance, **kwargs):
return
# Check if the content object has an 'average_rating' field
if not hasattr(content_object, 'average_rating'):
if not hasattr(content_object, "average_rating"):
return
# Calculate new average
# We query the Review model filtering by content_type and object_id
avg_rating = Review.objects.filter(
content_type=instance.content_type,
object_id=instance.object_id
).aggregate(Avg('rating'))['rating__avg']
avg_rating = Review.objects.filter(content_type=instance.content_type, object_id=instance.object_id).aggregate(
Avg("rating")
)["rating__avg"]
# Update field
content_object.average_rating = avg_rating or 0 # Default to 0 if no reviews
content_object.save(update_fields=['average_rating'])
content_object.save(update_fields=["average_rating"])