change specific field value in serializer class
<p>I have a model like this</p>

<pre><code>class ProjectTemplate(models.Model):
    project_template_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=64)
    description = models.TextField(max_length=255)
    created_date = models.DateTimeField(auto_now_add=True)
    modified_date = models.DateTimeField(auto_now=True)
    created_by = models.IntegerField(blank=True, null=True)
    modified_by = models.IntegerField(blank=True, null=True)
    activated = models.BooleanField(default=False)
    org_id = models.IntegerField(blank=False,null=False)

    class Meta:
        db_table = 'project_template'

    def __str__(self):
        return self.name
</code></pre>

<p>and a serializer class like this</p>

<pre><code>class ProjectTemplateSerializer(serializers.ModelSerializer): 
    class Meta:
         model = ProjectTemplate
</code></pre>

<p>in the created_by field i am storing the user id in the db, when listing the project templates, basically i'll get user id's for create_by field, </p>

<p>how to change my serializer class to get a dict like this </p>

<pre><code>{"user_id":id,"user_name":name}
</code></pre>

<p>for created_by field</p>

<p>Just like Sayse said, you'd better make a foreign key to a user like this:</p>

<pre><code>create_by = models.ForeignKey("User", related_name="project_user")
</code></pre>

<p>Then you can access the info from user like user_name or something by:</p>

<pre><code>class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ("id", "user_name")

class ProjectTemplateSerializer(serializers.ModelSerializer): 
    user = UserSerializer(source="user", read_only=True)

    class Meta:
         model = ProjectTemplate
         fields = (
            "id", "user",
         )
</code></pre>

python django django-rest-framework