D
D
Djigo2019-07-14 09:02:04
Django
Djigo, 2019-07-14 09:02:04

Django user entered a number, was that number added to the saved one and saved?

FORMS.PY:

class FishSpeedFarm(forms.ModelForm):
    class Meta:
        model = FishSpeed
        fields = ('maliyk',)

VIEWS.PY:
def fishspeed_farm(request):
    fishspeed_farm = FishSpeedFarm(instance=request.user.fishspeed)
    if request.method == "POST":
        fishspeed_farm = FishSpeedFarm(request.POST,request.FILES,instance=request.user.fishspeed)
        if fishspeed_farm.is_valid():
            fishspeed_farm.save()
    return render(request, 'fishspeed/farm.html',{
        'fishspeed_farm':fishspeed_farm,
})

MODELS.PY
class FishSpeed(models.Model):
    maliyk = models.IntegerField(default="0", verbose_name='Whitebait')

It is necessary that the user enters a number into the form and this number that he entered is added to another one that is already in the admin panel, how to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2019-07-14
@dimonchik2013

you update the field from the admin panel via
of = of +1
o.save()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question