Skip to content

Commit

Permalink
feat: total money raised
Browse files Browse the repository at this point in the history
  • Loading branch information
rb-25 committed Apr 17, 2024
1 parent 41b7e5f commit 0318dee
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
9 changes: 4 additions & 5 deletions gibspons/spons_app/views/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class CreateDisplayCompanyView(APIView):
permission_classes = [IsAuthenticated,IsApproved]
authentication_classes=[JWTAuthentication]
filter_backends = [SearchFilter, OrderingFilter, DjangoFilterBackend]
filterset_fields = ["name", "status","updated_at","user_id__username"]
search_fields = ["name","user_id__username","status"]
ordering_fields = ["name","status"]
filterset_fields = ["name"]
search_fields = ["name"]
ordering_fields = ["name"]
ordering = ["name"]

def get(self,request):
Expand All @@ -39,8 +39,7 @@ def get(self,request):

if not companies:
return Response({'detail': 'No companies found for the given organization ID'}, status=status.HTTP_404_NOT_FOUND)

#queryset = SearchFilter.filter_queryset(request, companies,queryset, view=self)

company_serializer = CompanySerializer(companies, many=True)
return Response(company_serializer.data, status=status.HTTP_200_OK)

Expand Down
3 changes: 3 additions & 0 deletions gibspons/spons_app/views/sponsorship.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def get(self, request):
sponsors = Sponsorship.objects.filter(contacted_by=user_id)
if not sponsors:
return Response({'detail': 'No companies found for the given User ID'}, status=status.HTTP_404_NOT_FOUND)
search_filter = SearchFilter()
queryset=search_filter.filter_queryset(request=request,queryset=sponsors,view=self)
sponsor_serializer = SponsorshipSerializer(sponsors, many=True)
return Response(sponsor_serializer.data, status=status.HTTP_200_OK)

Expand All @@ -108,6 +110,7 @@ class AddAcceptedView(APIView):

permission_classes=[IsAuthenticated,IsAdmin,IsApproved]
authentication_classes=[JWTAuthentication]

def post(self,request):
serializer=SponsorshipSerializer(data=request.data)
if serializer.is_valid():
Expand Down
13 changes: 13 additions & 0 deletions gibspons/users/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.db import models
from django.contrib.auth.models import AbstractUser
from spons_app.models import Event

class Organisation(models.Model):
name=models.CharField(max_length=255)
Expand All @@ -11,6 +12,18 @@ class Organisation(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
objects = models.Manager()

@property
def events(self):
return Event.objects.filter(organisation=self).all()

@property
def total_money_raised(self):
total=0
for event in self.events:
print(event.money_raised)
total+=event.money_raised
return total

class User(AbstractUser):
ROLE_CHOICES = [
('user', 'User'),
Expand Down
2 changes: 1 addition & 1 deletion gibspons/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ChangeRoleSerializer(serializers.Serializer):
class OrganisationSerializer(serializers.ModelSerializer):
class Meta:
model=Organisation
fields=['id','name','industry','location','invite_code','logo',]
fields=['id','name','industry','location','invite_code','logo','total_money_raised']
extra_kwargs = {
'name': {'required': False},
'invite_code': {'validators': []}, # Disable default uniqueness validator
Expand Down

0 comments on commit 0318dee

Please sign in to comment.