New to Django,

I want create a money system in my game that each user have a different 
coins

I tried add to User in views a variable 'balance'

My views.py:


   1. from monety.models import Gamer
   2. from django.contrib.auth.models import User 
   3. from .forms import RegisterForm
   4. 
   5. def registration(response):
   6.     if response.method == "POST":
   7.         form = RegisterForm(response.POST)
   8.         if form.is_valid():
   9.             user = User.objects.all().filter(username=username)[0] 
   10.             gamer = Gamer(myuser=user)
   11.             form.save()
   12.             gamer.save()
   13.             return redirect('/garden')
   14.     else:
   15.         form = RegisterForm()
   16. 
   17.     return render(response, "registration.html", {"form":form})

My models.py


   1. from django.db import models
   2. from django.contrib.auth.models import User 
   3.  
   4. class Gamer(models.Model):
   5.     myuser = models.OneToOneField(
   6.         User, 
   7.         on_delete=models.CASCADE
   8.     )
   9.     *balance = models.IntegerField(default=100)*

My forms.py


   1. from django.contrib.auth import login, authenticate
   2. from django.contrib.auth.forms import UserCreationForm
   3. from django import forms
   4. from django.contrib.auth.models import User
   5. 
   6. class RegisterForm(UserCreationForm):
   7.     email = forms.EmailField()
   8. 
   9.     class Meta:
   10.         model = User
   11.         fields = ["username", "email", "password1", "password2"]
   
I get "NameError: name 'username' is not defined" and I have no idea how to 
fix it to make it work

(sorry for my bad english)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e414e72-0665-475b-bcdd-1eb66d905b83n%40googlegroups.com.

Reply via email to