So I\'ve extended my user with the field score
like this:
models.py:
class UserProfile(models.Model):
user = models.OneToOneField(Us
You have to create a userprofile
for the user first:
profile = UserProfile.objects.create(user=request.user)
In your views.py you can use get_or_create
so that a userprofile is created for a user if the user doesn't have one.
player, created = UserProfile.objects.get_or_create(user=request.user)
UPDATE: For automatically creating user profiles every time a new user is made, use singals. In myapp/signals.py
do something like this:
@receiver(post_save, sender=User, dispatch_uid='save_new_user_profile')
def save_profile(sender, instance, created, **kwargs):
user = instance
if created:
profile = UserProfile(user=user)
profile.save()