Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
how to save multiple products in a single run

i have this issue trying to save de Order(detalle products) from my Sale, i don't know how to do it

class Sale(models.Model):
    sale_id = models.IntegerField(primary_key=True)
    cli = models.ForeignKey(Clientes ,on_delete=models.CASCADE,null=True)
    date_joined = models.DateField(default=datetime.now)
    subtotal = models.DecimalField(default=0.00, max_digits=9, decimal_places=2)
    iva = models.DecimalField(default=0.00, max_digits=9, decimal_places=2)
    total = models.DecimalField(default=0.00, max_digits=9, decimal_places=2)

class Order (models.Model):
    order_id = models.AutoField(primary_key=True)
    orden = models.IntegerField()
    sale_id = models.ForeignKey(Sale ,on_delete=models.CASCADE,null=True)
    codigo_producto = models.IntegerField()
    precio = models.IntegerField()
    cantidad = models.IntegerField()
above you can see my to models and here is how i called in my views

    def mod_venta(request,orden_actual=0):
    if request.session.get("codigo_usuario"):
        listaorder=Order.objects.all()
        listatabla=producto.objects.all()
        listacliente=Clientes.objects.all()
        if request.method=="GET":
            return validar(request, "venta.html",{"listaorder":listaorder,"listacliente":listacliente,"listatabla":listatabla})
        if request.method=="POST":
            if orden_actual==0:
                venta_nueva=Order(order_id=request.POST.get('orden_actual'),
                    codigo_producto=request.POST.get('codigo'),
                    precio=request.POST.get('precio'),
                    cantidad=request.POST.get('canti'))
                venta_nueva.save()

        return redirect("../venta/0")     
    else:
        return redirect("login")

and only try to save with a form, only saving one element in the "OrderDetalle", (i only work with for a month ) so I wanted to know how I could do to bring all the sales data in orders

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!