diff --git a/cookbook/serializer.py b/cookbook/serializer.py index a167b269c..ed4703588 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -122,7 +122,7 @@ class SpaceFilterSerializer(serializers.ListSerializer): # if query is sliced it came from api request not nested serializer return super().to_representation(data) if self.child.Meta.model == User: - data = User.objects.filter(userspace__space=self.context['request'].user.get_active_space()).all() + data = data.filter(userspace__space=self.context['request'].user.get_active_space()).all() else: data = data.filter(**{'__'.join(data.model.get_space_key()): self.context['request'].space}) return super().to_representation(data) diff --git a/cookbook/tests/api/test_api_username.py b/cookbook/tests/api/test_api_username.py index 51beb16d7..9ab5d3464 100644 --- a/cookbook/tests/api/test_api_username.py +++ b/cookbook/tests/api/test_api_username.py @@ -64,6 +64,7 @@ def test_list_space(u1_s1, u2_s1, u1_s2, space_2): assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 1 u = auth.get_user(u2_s1) + u.userspace_set.first().delete() UserSpace.objects.create(user=u, space=space_2) assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 1