Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
Efficient way in Django Models to store Items Purchased in a Transaction for a Commerce Store

I've created two simple Django Models. One model simply holds the bill details. The other one holds the list of items purchased in that Bill, linked through a foreign key relation. I'm stuck at a problem of creating a very large database with this implementation. Model Classes :

class Bill(models.Model):
    seller_id = models.ForeignKey(User , related_name = 'bill')
    amount = models.DecimalField(max_digits = 7 , decimal_places = 2)
    customer_id = models.ForeignKey(User , related_name = 'bill')

and

class BillItems(models.Model):
    bill = models.ForeignKey(Bill , related_name = 'items')
    product = models.ForeignKey(Product , related_name = 'items')
    quantity = models.DecimalField(max_digits = 6 , decimal_places = 3)

Now as I see it , after some time my database(MySql) would have a very large number of Bill Items' instances. Is there a better way to implement such a structure? OR Is there a way to optimize this structure?

Thanks and Regards.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

  • I don't think it's that big of a problem (it will at worst have x10 records than Bills table, which in DB world is not that big of a deal).
  • But if you have to, a better way would be to have a many to many relationship between Bills and Product. The only issue will be adding "quantity" to your bridge table. You can look at this answer on how to implement it.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda