13👍
A SocialAccount
model instance is available for users who signed up using their social account.
In your template, you can simply write:
Avatar URL: {{ user.socialaccount_set.all.0.get_avatar_url }}
UID: {{ user.socialaccount_set.all.0.uid }}
Date Joined: {{ user.socialaccount_set.all.0.date_joined}}
Last Login: {{ user.socialaccount_set.all.0.last_login}}
And for Full Name: {{ user.socialaccount_set.all.0.extra_data.name }}
For more information: Django allauth source
5👍
If you look at django-allauth source https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py#L7
This is an abstract model that represents all the methods all other specific service models have. Thus you could write
<p>You're logged in with {{ user.get_provider }} as {{ user }}.</p>
<img src="{{ user.get_avatar_url }}" />
- Unsupported lookup 'istartwith' for CharField or join on the field not permitted
- Django: taking input and showing output in the same page
- How to append extra data to the existing serializer in django
- Merge/join lists of dictionaries based on a common value in Python
- Django: lock particular rows in table
1👍
you can make for loop in set of socialaccount within foreignkey to user class, in the template it’s something like below :
{% for account in user.socialaccount_set.all %}
{% comment %} show avatar from url {% endcomment %}
<h2 style="text-transform:capitalize;">{{ account.provider }} account data</h2>
<p><img width="50" height="50" src="{{ account.get_avatar_url }}"/></p>
<p>UID: <a href="{{ account.extra_data.link }}">{{ account.uid }}</a></p>
<p>Username: {{ account.extra_data.username }}</p>
<p>First Name: {{ account.extra_data.first_name }}</p>
<p>Last Name: {{ account.extra_data.last_name }}</p>
<p>Dashboard Link:
<a href="{{ account.extra_data.link }}">{{ account.extra_data.link }}</a></p>
{% empty %}
<p>you haven't any social account please</p>
{% endfor %}
- Passing a variable in redirect in Django
- Django backup strategy with dumpdata and migrations
- Django A/B Split Testing Packages (None I've found are well-documented and up-to-date.)
0👍
So i got stock here too yesterday, i have gone round the internet for solution but none was looking as understandable as what i came up with…
After installation and configuration of the allauth package, i did the following:
-
create a signal.py file in app directory
-
Inside your venv locate the allauth package
-
Then navigate to allauth/socialaccount/models.py
-
This way you can have a better understanding on how to grab models from the allauth package or call other functions and classes
-
In app/signal.py do this:
from django.db.models.signals import post_save;p0- from django.dispatch import receiver from .models import Profile from allauth.socialaccount.models import SocialAccount# step 3 made this possible from django.contrib.auth.models import User @receiver(post_save, sender = SocialAccount) def create_profile(sender, instance, created, **kwargs): if created: # Grabbing data from social account to create profile for that user profile=Profile( user=instance.user, photo=instance.extra_data['picture'] ) profile.save() else: # Do something else
You see that the sender of the signal is the model "SocialAccount", because this model is always created during authentication, then grab the field "extra_data" which is a dictionary and then the key "[‘picture’]" from the JSON object in the field "extra_data"… I hope this works for you. Thank you
This way you are able to grab the values of the picture and also assign the user with a profile
- Django Celery Task Logging
- How to override method of the logging module
- Django: Change the DOM id at form field level
- How to format django template in Sublime Text