Answers for "django rest framework create"

12

install django rest framework

pip install djangorestframework
Posted by: Guest on September-10-2020
4

django rest framework

$ pipenv install djangorestframework
# or
pip install djangorestframework
Posted by: Guest on January-19-2021
0

User serializer in django rest framework

from rest_framework import serializers

class PostSerializer(serializers.ModelSerializer):
    user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
    class Meta:
        model = Post
Posted by: Guest on August-20-2020
0

User serializer in django rest framework

class EventSerializer(serializers.ModelSerializer):

    class Meta:
        model = models.Event
        exclude = ['user']


class EventView(APIView):

    def post(self, request):
        es = EventSerializer(data=request.data)
        if es.is_valid():
            es.save(user=self.request.user)
            return Response(status=status.HTTP_201_CREATED)
        return Response(data=es.errors, status=status.HTTP_400_BAD_REQUEST)
Posted by: Guest on August-20-2020

Code answers related to "django rest framework create"

Browse Popular Code Answers by Language