Reputation: 5833
What I want to achieve:
Upvotes: 4
Views: 975
Reputation: 5833
Depending on your desire provider you need to consider that the provider field from SocialApp and SocialAccount is a CharField with choices set to allauth.socialaccount.providers.registry.as_choices()
which is a generator that yields tuples such as ('facebook', 'Facebook')
, so we are basically interested in using 'facebook' for the provider field.
from django.contrib.sites.models import Site
from allauth.socialaccount.models import SocialApp, SocialAccount
user = User(...)
user.save()
sapp = SocialApp(provider='facebook', name='MyApp',
client_id='<your facebook app client id>',
secret='<your facebook app secret key>')
sapp.save()
sapp.sites.add(1) // or your site id
sacc = SocialAccount(uid="<your facebook uid>",
user=user, provider='facebook')
sacc.save()
Upvotes: 3