4

I'm trying to integrate python-social-auth into an existent Django project.

I want to use an existent model for a user's social accounts, instead of UserSocialAuth (my DB already has data with it, as well as some custom fields).

Is there some setting for it?

My custom model looks like this:

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?

1
  • 1
    I opened up a ticket to support extending the UserSocialAuth model. You shouldn't have to copy/paste all the existing UserSocialAuth model in your new model. It should be an abstract class that can be extended. That way you could add whatever new fields you wanted while leveraging the existing model: github.com/omab/python-social-auth/issues/698 Commented Jul 29, 2015 at 15:49

1 Answer 1

4

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'

For some reason this setting is documented only in the "Django" section of Python-social-auth's documentation, and not on the Settings page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.