• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

179
Vistas
how to find a way for a continuous cycle? using django?

new price is the price taken from the marketcapapi. I would like that every time the user buys coins, the coins are transferred to the ALGO_wallet leaving n_ALGO_coin at zero (= 0). The first time the user buys, everything is ok, the transfer is done, while the second time the data remains both in n_ALGO_coin and also in ALGO_wallet. I tried with a for loop but it tells me that the object is no interable

def buyalgomkt(request):
    new_price = algoValue()
    if request.method == "POST":
        form = PurchaseForm(request.POST)
        if form.is_valid():
            form.save(commit=False)
            profile = Profile.objects.get(user=request.user)
            if profile.USD_wallet > 0 and form.instance.max_spend_usd < profile.USD_wallet:
                form.instance.purchased_coin = form.instance.max_spend_usd / form.instance.price_mkt
                profile.n_ALGO_coin += form.instance.purchased_coin
                profile.USD_wallet -= form.instance.max_spend_usd
                profile.ALGO_Wallet += profile.n_ALGO_coin
                profile.n_ALGO_coin = profile.ALGO_Wallet - profile.n_ALGO_coin
                form.save()
                profile.save()
                name = request.user
                name.save()
                messages.success(request, 'Your order has been placed and processed')
            else:
                messages.warning(request, 'You do not have enough money')
            return redirect('purchase')

        else:
            return HttpResponseBadRequest()

    else:
        form = PurchaseForm()

    return render(request, 'coinmarketalgo/purchase.html', {'form': form, 'new_price': new_price})

.. how can I do?

class Profile(models.Model):
    _id = ObjectIdField()
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    ips = models.Field(default=[])
    subprofiles = models.Field(default={})
    n = random.randint(1, 10)
    n_ALGO_coin = models.FloatField(default=algoValue() * n)
    ALGO_Wallet = models.FloatField(default=0)
    purchased_coin = models.FloatField(default=0)
    USD_wallet = models.FloatField(default=10000)
    profit = models.FloatField(default=0)





class Purchase(models.Model):
    _id = ObjectIdField()
    max_spend_usd = models.FloatField(default=0)
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='purchases')
    price_mkt = models.FloatField(default=algoValue())
    datetime = models.DateTimeField(auto_now_add=True)
    purchased_coin = models.FloatField(default=0)
    profile = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name='profile')

about 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda