42👍
In your serializer class inherit from ModelSerializer instead of Serializer class since the later doesn’t call create() method implicitly.
class PeopleSerializer(serializers.ModelSerializer):
The above change would do your job!
3👍
Please check your indentation, that ‘create’ function should be inside that Serializer class, as below example.
class StudentSerializer(serializers.Serializer):
name = serializers.CharField(max_length=111)
roll = serializers.IntegerField()
city = serializers.CharField(max_length=722)
def create(self,validated_data):
return Student.objects.create(**validated_data)
- Installed Virtualenv and activating virtualenv doesn't work
- Django Postgres ArrayField vs One-to-Many relationship
- Using existing field values in django update query
-1👍
Check if the keys inside data exactly match model attributes when you try to create an object of a particular model using the model serializer
- Django NodeNotFoundError during migration
- A good way to encrypt database fields?
- Django filter on APIView
-1👍
Please check your indentation, that ‘create’ function should be within that Serializer class Hopefully it will work.
- Pass JSON to JS using Django render
- Django: Possible to load fixtures with date fields based on the current date?
-1👍
from rest_framework import serializers
from .models import Student
class StudentSerializer(serializers.Serializer):
name=serializers.CharField(max_length=555)
def create(self,validated_data):
return Student.objects.create(**validated_data)enter image description here
- PIL – libjpeg.so.8: cannot open shared object file: No such file or directory
- Django update on queryset to change ID of ForeignKey
- Django+Nginx+uWSGI = 504 Gateway Time-out
- Why use South during initial development?
- Django Forms: Hidden model field?