Groups
Groups
Sign in
Groups
Groups
Django users
Conversations
About
Send feedback
Help
Adding to User new variable / money system in game
20 views
Skip to first unread message
Gracjan Chudziak
unread,
Sep 1, 2020, 6:21:24 PM
9/1/20
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
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:
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)
Reply all
Reply to author
Forward
0 new messages