0

I can create new custom user profile with create_profile pipeline function. But also I want to update profile details, if user (or profiles) exist. I couldn't figure out what I need add this function.

utils.py

def create_profile(strategy, backend, details, response, user, *args, **kwargs):
if Profiles.objects.filter(user=user).exists():
    if backend.name == 'facebook':
        Profiles(user=user).gender = response.get('gender')
        Profiles(user=user).fb_link = response.get('link')
        Profiles(user=user).timezone = response.get('timezone')
        Profiles(user=user).birthdate = response.get('birthday')
        Profiles(user=user).email = response.get('email')
        Profiles(user=user).fb_id = response.get('id')
else:
    new_profile = Profiles(user=user)
    if backend.name == 'facebook':
        new_profile.gender = response.get('gender')
        new_profile.fb_link = response.get('link')
        new_profile.timezone = response.get('timezone')
        new_profile.birthday = response.get('birthday')
        new_profile.email = response.get('email')
        new_profile.fb_id = response.get('id')  
    new_profile.save()

return kwargs

myapp.models.py

class Profiles(models.Model):
user = models.OneToOneField(User, unique=True, null=True)
first_name = models.CharField(max_length=250, blank=True, null=True)
last_name = models.CharField(max_length=250, blank=True, null=True)
middle_name = models.CharField(max_length=200, blank=True, null=True, default="")
profile_img = models.URLField(upload_to='avatars/',null=True, blank=True, default="http://www.murketing.com/journal/wp-content/uploads/2009/04/brightkite.png")
birthdate = models.DateField(null=True, blank=True)
locale = models.CharField(max_length=250, blank=True, null=True)
email = models.CharField(max_length=250, blank=True, null=True)
fb_id = models.BigIntegerField(blank=True, null=True, verbose_name='Facebook ID')
Alkindus
  • 2,064
  • 2
  • 16
  • 16
  • Could you clarify the question? What is the problem with the function? – elas Feb 18 '15 at 01:14
  • I can create a new profile with this code but I coulnt update exisitng profile. For example I want to update profiles.gender if Profiles exists. How can I update it? – Alkindus Feb 18 '15 at 10:30

0 Answers0