R
R
Ribachok2020-04-15 23:14:42
Django
Ribachok, 2020-04-15 23:14:42

How to change integer value through views?

hello. The question seems simple, but I was not able to solve this problem.
There is a model

class Profile(models.Model):
     - - -
    monetki = models.IntegerField(default=0)

And you need to take these same coins through views.py. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WStanley, 2020-04-16
@Ribachok

What exactly is needed?

from app_name.models import Profile

profiles = Profile.objects.all()
# получить
for profile in profiles:
    print(profile.monetki)

# присвоить
profiles = Profile.objects.filter(monetki=0)
for profile in profiles:
    profile.monetki = 25
    profile.save()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question