from rest_framework import viewsets
from .models import FinanceEntry
from .serializers import FinanceSerializer
class FinanceViewSet(viewsets.ModelViewSet):
 serializer_class=FinanceSerializer; filterset_fields=['scope','campus','direction','category','approved']; search_fields=['description','reference']; ordering_fields=['transaction_date','amount']
 def get_queryset(self):
  queryset=FinanceEntry.objects.select_related('campus','submitted_by','submitted_by__member_profile')
  return queryset if self.request.user.is_staff else queryset.filter(submitted_by=self.request.user)
 def perform_create(self,serializer): serializer.save(submitted_by=self.request.user)
