Rach Odwyer
Rach Odwyer

Reputation: 184

Django REST Framework setting to change the auto added 'Id' to 'djangoID'

I'm happy to let DRF add an 'ID' column to my model if no primary key is defined.

Is there a way in settings to make this name more appropriate?

eg 'ID' would actually be 'djangoID'

Upvotes: 0

Views: 378

Answers (1)

Astik Anand
Astik Anand

Reputation: 13047

Actually, I will not recommend doing something like that. But if you want to change you can do it by specifying a custom primary key.

Just specify primary_key=True on one of your fields(here for example djangoID). If Django sees you’ve explicitly set Field.primary_key, it will not add the automatic id column.

As it will not automatically add id column you've effectively renamed it.

Upvotes: 1

Related Questions