简体   繁体   中英

Restrict certain model fields for user in Django Restful API Framework

I am using Django . I have a model with 10 fields. I have to restrict users in using only a few fields while other parameters are to be populated only at the backend (hidden parameters from a user).

If the user is sending few parameters to the rest API server , an error is displayed saying that " other fields are required ". So, I tried to add blank=true null=true to the hidden parameters.

However, I feel that this is not the right method. The user can still use hidden parameters if he gets to know the parameter name.

What is the right way to specify model parameters as 'exposed to users' or 'hidden from users'? Is it done through serializers?

Django REST framework serializers allows you to expose only a subset of the fields on your model. see http://www.django-rest-framework.org/api-guide/serializers#specifying-which-fields-should-be-included

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM