Files
shopback/reviews/admin.py
Beyhan Oğur d9f1ea341e first commit
2026-04-26 22:27:56 +03:00

17 lines
795 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.contrib import admin
from .models import Rating
@admin.register(Rating)
class RatingAdmin(admin.ModelAdmin):
list_display = ('content_object', 'user', 'score', 'created_at')
list_filter = ('score', 'created_at', 'content_type')
search_fields = ('user__username', 'user__email', 'comment')
readonly_fields = ('created_at', 'updated_at')
# GenericForeignKey alanlarını admin panelinde daha düzgün göstermek için
# content_object alanını list_display'e ekledik, bu sayede hangi nesneye oy verildiği görülebilir.
def get_queryset(self, request):
# N+1 sorununu önlemek için related alanları prefetch edelim
return super().get_queryset(request).select_related('user', 'content_type').prefetch_related('content_object')