2

From this post: How can I get the user's facebook id with django-allauth? there is a simple way of accessing extra information from a user's social account within a template (e.g. looking at the entries in {{ user.socialaccount_set.all.0.extra_data }}).

I would like to grab this information in a view, rather than the template, ideally looping through all connected social accounts, and grabbing the more desirable information from each, and then passing only that information to the template.

Does anyone know how to access socialaccount_set.all from within a view?

Community
  • 1
  • 1
voisin
  • 267
  • 2
  • 6

3 Answers3

4

I know it's been over a year since this question was posted, but I couldn't find the answer anywhere.

This is how I did it finally, in case this helps anyone in future:

#views.py

user.socialaccount_set.all()[0].extra_data
Amit
  • 1,620
  • 1
  • 15
  • 24
2

Here is an alternative for accessing in a view any information stored for a user:

from allauth.socialaccount.models import SocialAccount

social_info = SocialAccount.objects.filter(user=request.user)
fb_id = SocialAccount.objects.filter(user=request.user, provider='facebook')[0].uid
1

Continue the above answer, maybe you can try to use:

SocialAccount.objects.filter(user=request.user)[0].extra_data['email']

It will get the extra data for the email account. Hope this helpful :)

Zakky M
  • 31
  • 2