Answer the question
In order to leave comments, you need to log in
How to create userlevel after registration?
There is a UserLevel model. After registration, you need to create the first level.
There are two decorators in models.py 'create_user_profile' and 'save_user_profile' and a social alert.
class UserLevel(models.Model):
level = models.ForeignKey(Level, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
progress = models.IntegerField(default=0)
access = models.BooleanField(default=False)
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.userprofile.save()
@receiver(user_signed_up)
def set_initial_user_names(request, user, sociallogin=None, **kwargs):
preferred_avatar_size_pixels = 25
if sociallogin:
if sociallogin.account.provider == 'google':
picture_url = sociallogin.account.extra_data['picture']
if sociallogin.account.provider == 'facebook':
picture_url = "http://graph.facebook.com/{0}/picture?width={1}&height={1}".format(
sociallogin.account.uid, preferred_avatar_size_pixels)
user.userprofile.avatar_url = picture_url
user.userprofile.save()
{ "id": 8, "progress": 0, "access": true, "level": 1, "user": 3 }
?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question