Issue
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 !!
Solution
What happens if you do something as following :
groups = Group.objects.all().exclude(id=10)
Answered By - em1le
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.