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:
- from monety.models import Gamer
- from django.contrib.auth.models import User
- from .forms import RegisterForm
- def registration(response):
- if response.method == "POST":
- form = RegisterForm(response.POST)
- if form.is_valid():
- user = User.objects.all().filter(username=username)[0]
- gamer = Gamer(myuser=user)
- form.save()
- gamer.save()
- return redirect('/garden')
- else:
- form = RegisterForm()
- return render(response, "registration.html", {"form":form})
My models.py
- from django.db import models
- from django.contrib.auth.models import User
- class Gamer(models.Model):
- myuser = models.OneToOneField(
- User,
- on_delete=models.CASCADE
- )
- balance = models.IntegerField(default=100)
My forms.py
- from django.contrib.auth import login, authenticate
- from django.contrib.auth.forms import UserCreationForm
- from django import forms
- from django.contrib.auth.models import User
- class RegisterForm(UserCreationForm):
- email = forms.EmailField()
- class Meta:
- model = User
- 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)
(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+unsubscribe@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.
No comments:
Post a Comment