I have following response data
[ { "id": 7, "name": "Default Group", "permissions": [ 22, 24 ] }, { "id": 10, "name": "Another Group", "permissions": [ 1, 2, 22, 24 ] }, { "id": 11, "name": "New Group", "permissions": [ 10, 11, 12, 5, 6, 7, 8 ] }]
But I want to remove the dictionary whose id = 10 from the response data ,how can I do that ?
I have following lines of code..
class GetUserGroupList(APIView): def post(self, request, *args, **kwargs): groups = Group.objects.all() serializer = GroupSerializer(groups, many=True) return Response(serializer.data)
In serializers.py
class GroupSerializer(serializers.ModelSerializer): class Meta: model = Group fields = ('id', 'name', 'permissions',)
Any help would be appreciated !!
Advertisement
Answer
What happens if you do something as following :
groups = Group.objects.exclude(id=10)