[Answer]-Django – running query filter by user

0👍

✅

I ended up getting it to work by focusing on stripping down my view to the bare bones and building it up again. This worked –

def index(request):
    userid = None
    if request.user.is_authenticated():
        userid = request.user.id
    queryset = UserFile.objects.filter(userid=userid).values_list('fileid', 'grant_date', 'revoke_date')
    return JSONResponse(queryset)

1👍

As I understand this you try to filter on username=.... where there is no field username in your UserFile model additionally the vendorid is missing as well?

The error might be resulting from the fact that Django can’t resolve the ‘vendorid’ string since there is no corresponding field and thatswhy states that this str is not callable.

Might be helpful to see the complete stack and in case that the Model is only partly documented to have the complete Model.

Leave a comment