0

Everything works until I try to Return JsonResponse
I'm looping through the list, which contains usernames then passing those usernames to the models which return basic user information and storing those values in a variable which I later added to the list.

def jsonresponse(request, username):

   Current_User = User.objects.get(username=username)
   #List of who this user follows
   followingList = Follower.objects.filter(follower=int(Current_User.id))

   UsersInfo = []
   for user in followingList:
       singleUser = User.objects.filter(username=user.following).values( 'username','bio', 'profile_image')
       UsersInfo.append(singleUser)


   results = User.objects.filter(username=Current_User).values( 'username','bio', 'profile_image') **This Works**

   return JsonResponse({'results':list(results), 'UsersInfo':list(UsersInfo)})

This works 'results':list(results), This doesn't 'UsersInfo':list(UsersInfo)

print(results) gives me this:

<QuerySet [{'username': 'John', 'bio': 'Hello, im new!', 'profile_image': 'images/ape_xhRtC2R.jpg'}]>

print(UsersInfo) gives me this:

[<QuerySet [{'username': 'Tristan', 'bio': 'Hello, im new!', 'profile_image': 'images/1-scary-tiger-head-robbybubble.jpg'}]>, <QuerySet [{'username': 'William', 'bio': 'Hello, im new!', 'profile_image': 'images/ape_PvPNwCP.jpg'}]>]

Any help would really be appriciated

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
greensky
  • 19
  • 5

1 Answers1

0

Replace

singleUser = User.objects.filter(username=user.following).values( 'username','bio', 'profile_image')

to

singleUser = User.objects.get(username=user.following).values( 'username','bio', 'profile_image')

You just get user object insted of QuerySet each time.

Waldemar Podsiadło
  • 1,365
  • 2
  • 5
  • 12