Answer the question
In order to leave comments, you need to log in
How to save data for an authorized user?
I have
models.py model
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='userprofile')
points = models.IntegerField(default=0)
<form action="" method="POST">
<button type="submit">+</button>
</form>
urlpatterns = [
url(r'^$', demo),
url(r'^demo/$', demo),
]
def demo(request):
if request.method == "POST":
# тут я не понимаю как обратиться к "points" из модели "UserProfile"
#что бы добавить 1 и сохранить в базу
return render(request, 'app/demo.html')
def demo(request):
if request.method == "POST":
profile = UserProfile.objects.get(user=request.user)
profile.points += 1
profile.save()
return render(request, 'app/demo.html')
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