Z
Z
zlodiak2018-07-01 23:36:23
Django
zlodiak, 2018-07-01 23:36:23

How to exclude a field from a selection?

The front requests data from the back at the following address:

http://127.0.0.1:8000/users/[email protected]

This is the response from the server:
fields:{fname: "kalinin", lname: "sergey", login: "[email protected]", pass_hash: "D033E22AE348AEB5660FC2140AEC35", created_date: "2018-07-01T10:53:58Z", …}
model:"app_users.user"
pk:1

I would like to exclude the pass_hash field from the response on the server side. Please help me fix the back controller:
def get_user(request):
    login_ = request.GET['login']
    user = User.objects.filter(login=login_)
    user_serialized = serializers.serialize('json', user) 
    return JsonResponse(user_serialized, safe=False)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Zakharov, 2018-07-01
@zlodiak

As far as I remember, you can set the fields for serialization:

user_serialized = serializers.serialize('json', user, fields=('fname', 'lname' ...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question