def remove_participant(request, grp=None, id=None): group = models.Group.objects.get(pk=grp) usr = User.objects.get(pk=id) group.participants.remove(usr) group.save() return JsonResponse(UserSerializer(group.participants, many=True).data, safe=False)
class GroupSerializer(serializers.ModelSerializer): messages = serializers.SerializerMethodField('paginated_messages') participants = UserSerializer(many=True) class Meta: model = Group fields = "__all__" def paginated_messages(self, obj): messages = Bubble.objects.filter(group=obj) paginator = messaging.views.api.MessagingPaginator() page = paginator.paginate_queryset(messages, self.context['request']) serializer = BubbleReadSerializer( page, many=True, context={'request': self.context['request']}) return serializer.data
class BubbleReadSerializer(BubbleSerializer): sender = UserSerializer(many=False)