[Python] how to import csv data into django models

Discussão em 'Python' iniciado por Stack, Janeiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have some CSV data and I want to import into django models using the example CSV data:

    1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
    2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dark green";
    3;"02-01-101103";"Worm Gear HRF 50";"Ratio 1 : 30";"input shaft, output shaft, direction A, color dark green";
    4;"02-01-101104";"Worm Gear HRF 50";"Ratio 1 : 40";"input shaft, output shaft, direction A, color dark green";
    5;"02-01-101105";"Worm Gear HRF 50";"Ratio 1 : 50";"input shaft, output shaft, direction A, color dark green";


    I have some django models named Product. In Product there are some fields like name, description and price. I want something like this:

    product=Product()
    product.name = "Worm Gear HRF 70(02-01-101116)"
    product.description = "input shaft, output shaft, direction A, color dark green"
    product.price = 100

    Continue reading...

Compartilhe esta Página