Django-restframework - use the same value on differents fields

I'm building an API using Django-restframework.
models.py

class Researches(models.Model):
    research_id = models.BigAutoField(primary_key=True)

I would like to use the same value on two differents fileds, like:

[
    {
        "research_id": 1,
        "id": 1
    },
]

Is it possible?

You need to do something like this:

class ResearchesSerializer(
    serializers.ModelSerializer
):
    id = serializers.IntegerField(
        source="research_id", read_only=True
    )
    class Meta:
        model = Researches
        fields = (
            "research_id",
            "id",

        )

for ref: https://www.django-rest-framework.org/api-guide/serializers/#specifying-fields-explicitly

Back to Top