There is a route /group/task, every time it is called, the log will be 
generated.

This is views.py

class GroupViewSet(viewsets.ViewSet):
        ....
        @detail_route(methods=['post'], url_path='task')
        def get_task(self, request, pk=None):
                group = get_object_or_404(Group, pk=pk)
                #group = ServerSerializer(group) <--- tried but not work

                data = {
                    "group": group,
                    #"group": group.data, <--- tried but not work
                }
                log_serializer = LogSerializer(data=data)
        if log_serializer.is_valid(raise_exception=True):
            log_serializer.save()


This is serializer.py

class GroupSerializer(serializers.ModelSerializer):
class Meta:
    model = Group
    fields = ('id', 'name')

class LogSerializer(serializers.ModelSerializer):
    group = GroupSerializer()
    class Meta:
        model = Log
        fields = ('group', 'created')


The post responese:

{
    "group": {
        "non_field_errors": [
            "Invalid data. Expected a dictionary, but got group."
        ]
    }}

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to