Python-social-auth and Django, replace UserSocialAuth with user model

I am trying to integrate python-social-auth into an existing Django project.

I want to use the existing model for social user accounts, instead of UserSocialAuth (my database already has data with it, as well as with some custom fields).

Are there any settings for this?

My custom model is as follows:

class Channel(models.Model, DjangoUserMixin):
    PROVIDER_CHOICES = (
        ('twitter', 'Twitter'),
    )

    uid = models.CharField(max_length=255)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True,
                             related_name='channels')

    provider = models.CharField(max_length=32, choices=PROVIDER_CHOICES)
    extra_data = JSONField()

    class Meta:
        unique_together = ('provider', 'uid')

    @classmethod
    def get_social_auth(cls, provider, uid):
        try:
            return cls.objects.select_related('user').get(provider=provider, uid=uid)
        except Channel.DoesNotExist:
            return None

    username_max_length = 255
    user_model = get_user_model()

Any ideas?

+4
source share
1 answer

Solved by creating a custom Storage:

# channels/models.py
# ...

class CustomSocialStorage(DjangoStorage):
    """To replace UserSocialAuth model with Channel"""
    user = Channel

And registering it in the settings:

SOCIAL_AUTH_STORAGE = 'proj.channels.models.CustomSocialStorage'

- "Django" Python-social-auth, .

+4

All Articles