예제 #1
0
 def create_user_profile(sender, instance, created, **kwargs):
     """When a new user is created, create a corresponding profile."""
     if created:
         profile = Profile.objects.create(user=instance)
         profile.avatar.save(instance.username,
                             File(generate_identicon(instance)))
         profile.save()
예제 #2
0
 def save(self, *args, **kwargs):
     """Fix the IntegrityError when creating a new user and modifying default profile."""
     if self.pk is None:
         p = Profile.objects.filter(user=self.user)
         p.delete()
         super(Profile, self).save(*args, **kwargs)
         self.avatar.save(self.user.username, File(generate_identicon(self.user)))
     else:
         super(Profile, self).save(*args, **kwargs)