2👍
here how I solved it using SerializerMethodField,
emp_id = serializers.SerializerMethodField('emp_id_from_nickname')
here, emp_id_from_nickname is the method, which helps to add value into my field.
def emp_id_from_nickname(self, model_obj):
get_id = Employee.objects.get(usename=model_obj.username).emp_id
return get_id
class Meta:
model = User
fields = ('id', 'username', 'first_name', 'last_name', 'emp_id')
0👍
Change your serializer field to,
emp_id = serializers.PrimaryKeyRelatedField(queryset=Employee.objects.all())
Source:stackexchange.com