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:
parent
4a7f720773
commit
ae92fc2027
1 changed files with 4 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue