Skip to content

Commit

Permalink
Fix bug where num_visits was not user specific
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorley15 committed Nov 16, 2024
1 parent 4a7f720 commit ae92fc2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/server/worldtravel/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def get_num_regions(self, obj):
return Region.objects.filter(country=obj).count()

def get_num_visits(self, obj):
return VisitedRegion.objects.filter(region__country=obj).count()
request = self.context.get('request')
if request and hasattr(request, 'user'):
return VisitedRegion.objects.filter(region__country=obj, user_id=request.user).count()
return 0

class Meta:
model = Country
Expand Down

0 comments on commit ae92fc2

Please sign in to comment.