1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-24 15:29:36 +02:00

Fix bug where num_visits was not user specific

This commit is contained in:
Sean Morley 2024-11-16 16:47:21 -05:00
parent 4a7f720773
commit ae92fc2027

View file

@ -19,7 +19,10 @@ class CountrySerializer(serializers.ModelSerializer):
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