0

I am using:

  • django-social-auth v 0.7.19
  • django 1.4.3

models.py:

class UserProfile(models.Model):
    user = models.ForeignKey(User)
    username = models.CharField(max_length = 64, blank = True, null = True)
    last_login = models.DateField(blank = True, null = True)
    is_active = models.BooleanField(blank = True)

social_auth pipeline.py:

from social_auth.backends.pipeline.user import create_user


def create_user(backend, details, response, uid, username, user=None, *args,
            **kwargs):

    if user:
        return {'user': user}
    if not username:
        return None

    user, created = User.objects.get_or_create(username = username)
    profile, created = UserProfile.objects.get_or_create(user = user)

    return {
        'user': user,
        'profile' : profile,
        'is_new': True
    }

Problem:

  1. When I take out the fields username, last_login and is_active from my model, the social auth would give me a DataBaseError as these columns are necessary. I am taking ForeignKey User but it cannot detect it.

  2. I am overriding the create_user method of social auth to create my user and their profile. When the function returns, a user and profile is created but still it redirects on the error page. Cannot figure out why.

Zain Khan
  • 3,753
  • 3
  • 31
  • 54

1 Answers1

0

Try changing your profile creation with this code:

profile, created = UserProfile.objects.get_or_create(user=user, defaults={
    'username': user.username,
    'last_login': date.today(),
    'is_active': True
})

Or add some default values to those fields.

Edit: keyword argument is defaults not default.

omab
  • 3,721
  • 19
  • 23