I'm using django-facebook and I would like the profile-picture to be the picture of my user when they register with facebook.
In my custom User model (Userprofile) I have a
profilpic = models.ImageField(...)
I also have this function in my models.py:
def create_facebook_profile(sender, instance, created, **kwargs):
if not created:
return
UserProfile.objects.create(user=instance)
post_save.connect(create_facebook_profile, sender=User)
I was wondering if it's possible to use the facebook profile picture as the 'profilpic' of my user.
I tried to do that:
def create_facebook_profile(sender, instance, created, **kwargs):
if not created:
return
UserProfile.objects.create(user=instance)
user_data = json.loads(instance.raw_data)
user_pic = user_data.get('image')
user = request.user
user.userprofile.profilpic = user_pic
user.save()
post_save.connect(create_facebook_profile, sender=User)
But it doesn't work. Any idea on how to do that?