nataila
nataila

Reputation: 1619

how to change default 'pk' to 'id' or others in django-rest-framework?

like this:
the default field in django-rest-framework'route is pk

@detail_route(methods=['GET'])
    def run(self, reuqest, pk):
       print pk
       return xxx 

this url's base_url is sched
then I get 0.0.0.0:8000/sched/12/run/
I can get pk=12 in method run

now I want change pk to id
make me can do like this:

@detail_route(methods=['GET'])
    def run(self, reuqest, id):
       print id
       return xxx

how can i change it?

Upvotes: 1

Views: 291

Answers (1)

nataila
nataila

Reputation: 1619

set lookup_field in class, that can fixed this question

Upvotes: 1

Related Questions