The create function is giving me the following error:
AttributeError: 'dict' object has no attribute 'user'
Looks like request.user does not exist in this serializer. Is there a way to retrieve the user id in serializer? Or is this not possible?
class EmployeeQuestionSerializer(serializers.ModelSerializer):
class Meta:
model = EmployeeQuestion
fields = (
'id',
'employee',
'question',
'attempted',
'passed',
)
def create(self, request):
serializer = EmployeeQuestionSerializer(employee=request.user.pk)
if serializer.is_valid():
return serializer.save();
def update(self, instance, validated_data):
instance.attempted = validated_data.get('attempted')
instance.passed = validated_data.get('passed')
instance.save()
return instance
createhas norequestparameter, it only has a dictionary with data.request.useris available in yourserializer.contextstackoverflow.com/questions/63039105/…