Django Import CSV into Model

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ส.ค. 2024
  • In this django tutorial we go through one of may ways to import data from an CSV file into an existing django model.
    Code repository:
    github.com/ver...
    🐱‍🏍Would you like to SUPPORT US FURTHER so that we can make even more great content - Please consider joining our members community.
    / @veryacademy
    👍SUBSCRIBE to get more free tutorials, courses and code snippets!
    / @veryacademy

ความคิดเห็น • 89

  • @rxlvnd3397
    @rxlvnd3397 หลายเดือนก่อน

    thank you for the tutorial! If anyone has trouble with the ordering of columns after you've imported the csv into the model's database, you could reorder the columns in your csv the exact same way the columns are ordered in the empty database. It might take a bit of time, but it definitely works.

  • @Troglodyte2021
    @Troglodyte2021 3 ปีที่แล้ว +7

    If you can teach your fans (me included) how to set up a button in the admin site, let an admin upload a csv/excel file and then insert the data into database, that would be a giant move. People who are real web developers need to do this for their clients.

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว +3

      Sure we can do this 👍

    • @hafeezpp
      @hafeezpp 3 ปีที่แล้ว +1

      Use django-excel library 👍

    • @g.6013
      @g.6013 3 ปีที่แล้ว +5

      use django import-export super easy and usefull

  • @salahdz2834
    @salahdz2834 3 ปีที่แล้ว +2

    That's a different approach, I like it. That's great tutorial.

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว

      Thanks - its all situational. 👍

  • @baloney_sandwich
    @baloney_sandwich ปีที่แล้ว +1

    I would use pandas to read the csv, save u time n give u extra tools. Good video

  • @jamesmoulds6960
    @jamesmoulds6960 3 ปีที่แล้ว +2

    Best presented tutorial I could find on this topic. Thanks. Now just need to figure out how to automate this!? Can anyone point me to any resource that will automate the import?

  • @leo44370
    @leo44370 3 ปีที่แล้ว +1

    Late night weekend updates. Working hard 👍

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว

      Mate, this is just a bad habit.

  • @aleksandarradovic2960
    @aleksandarradovic2960 2 ปีที่แล้ว +1

    at 14:34 when you check the data, on line 11099 there is a date that is improperly formatted. I wonder if it made it in the database. That is why I always set filter in Excel and quickly loop through the drop down to see if all dates are set inside years, or if there are some values stored as text or otherwise. Alternatively you can create 3 additional columns and run functions: year(date cell), month(date cell), day(date cell) and in the fourth column recreate your date with certainty they will all be equally formatted. Of course, afterwards you delete all additional columns and copy the forth one in the date column.

  • @gunahawk6893
    @gunahawk6893 2 ปีที่แล้ว

    Made by day by finding your channel

  • @DaisyRahman
    @DaisyRahman 11 หลายเดือนก่อน

    This is helping me a lot! Thank you so much :)

  • @ayeshrodrigo2197
    @ayeshrodrigo2197 3 ปีที่แล้ว +3

    Thank you. This is very useful.. How can we import a large data set quickly like you did using Django itself (extending a button for user) rather than doing it using the shell from backend.

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว

      Hope I answered this one in the other tutorial.

    • @g.6013
      @g.6013 3 ปีที่แล้ว

      @@veryacademy can you tellme where is this tutorial you are talking about thanks for your great tutorial

  • @westporthardware5179
    @westporthardware5179 3 ปีที่แล้ว +2

    Hi,
    I m using my data and followed step by step , I encountering error of data type mismatch , even I have deleted data and leave only 1 Colin , still doesn’t work

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว

      Hi, did you fix it. Lets make sure that your database data types are correct and you have lined up the fields with the correct headings of the CSV file

    • @westporthardware5179
      @westporthardware5179 3 ปีที่แล้ว

      @@veryacademy i managed to fix that. Quick question, if the data uploaded everyday , do we need to clean the data everytime or there is a quick workaround ?

  • @franciskalonjimbuyamba5215
    @franciskalonjimbuyamba5215 2 ปีที่แล้ว +2

    This was a really great video. How would you do this if you had a remote PostgreSQL DB as opposed to sqlite?

    • @veryacademy
      @veryacademy  2 ปีที่แล้ว +1

      Have you tried hooking up a Postgres db?

    • @samueltaylor2757
      @samueltaylor2757 2 ปีที่แล้ว +1

      Hi! I did this using a postgres client link DBeaver which is really intuitive to use

  • @mounirben9370
    @mounirben9370 3 ปีที่แล้ว +1

    Excellent tutorial!

  • @KlausBentes
    @KlausBentes ปีที่แล้ว

    Huge help! Thank you very much! 🙏

  • @owningglory39
    @owningglory39 10 หลายเดือนก่อน

    Thank you

  • @valeriiastartseva1612
    @valeriiastartseva1612 ปีที่แล้ว +1

    hi! how to cancel import csv file to table? if i import wrong file

    • @veryacademy
      @veryacademy  ปีที่แล้ว

      You don't cancel unfortunately, you revert to the backup you made before you tried to import the csv file

  • @normanluismadrid422
    @normanluismadrid422 2 ปีที่แล้ว +1

    great video! quick question, when i want to update existing objects via import, and my csv has blank cells for a column, it replaces the data in my objects with that blank empty string, how do i stop django import from doing this?

  • @whitehacker6171
    @whitehacker6171 8 หลายเดือนก่อน

    running sqlite3.exe command giving me error like 'not recognized', what to do?

  • @Anilkumar-lk2uw
    @Anilkumar-lk2uw ปีที่แล้ว

    Thanks bro

  • @rajarshimazumder2350
    @rajarshimazumder2350 ปีที่แล้ว

    very much helpful thanku

  • @musicvstime9559
    @musicvstime9559 2 ปีที่แล้ว +1

    Thanks ! but sir how can i do this using postgresql ? i can't find reasorses could help with that .

    • @veryacademy
      @veryacademy  2 ปีที่แล้ว +1

      Setup django in the settings with Postgres and then it should be the same process?

  • @dinuzakbayev4349
    @dinuzakbayev4349 2 ปีที่แล้ว

    Could you please also post a video how to export Django database models to Excel template with some formatting via the Django admin?

  • @eesakamaldien1917
    @eesakamaldien1917 2 ปีที่แล้ว +1

    hi what if one of the models had a foreign key? then how would this be applied?

    • @saif9170
      @saif9170 2 ปีที่แล้ว

      Do you find solutions of it? Please share with me!

    • @eesakamaldien1917
      @eesakamaldien1917 2 ปีที่แล้ว +1

      @@saif9170 yes I will share link later to answer

    • @saif9170
      @saif9170 2 ปีที่แล้ว

      @@eesakamaldien1917 Please share !!

    • @eesakamaldien1917
      @eesakamaldien1917 2 ปีที่แล้ว

      @@saif9170 what is your Facebook I will first need to know what you trying

  • @saidhofiani2670
    @saidhofiani2670 ปีที่แล้ว

    When I put the book model in the settings it says ""ModuleNotFoundError: No module named"

  • @dennohnjogu4028
    @dennohnjogu4028 2 ปีที่แล้ว +1

    how would one handle relationships?

    • @veryacademy
      @veryacademy  2 ปีที่แล้ว +1

      Be the best you can, make sure they have lots of money and get married as soon as possible

    • @dennohnjogu4028
      @dennohnjogu4028 2 ปีที่แล้ว

      @@veryacademy hahaha..you know what i meant

  • @yasayah7289
    @yasayah7289 2 ปีที่แล้ว +1

    This is great thank you! New subscriber. Be nice for users with permissions to drag n drop a csv and dynamically update the database and site page with inventory and totals, as opposed to individually adding inventory items one by one.

  • @cristobaljvp
    @cristobaljvp 3 ปีที่แล้ว +2

    Thanks for the video! pretty nice info. How would you go about adding the data from a pandas dataframe to the DB?

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว

      You can do - its all situational - I wouldn't bring in pandas just for that - if I was working panda anyway - then why not, its an option. Any its all very situational.

    • @venkyslarky8817
      @venkyslarky8817 2 ปีที่แล้ว

      @@veryacademy Hello man. Thanks for awesome info. Can you make a separate tutorial or give some reference for the same of using management command with pandas.

  • @rakeshroy7118
    @rakeshroy7118 ปีที่แล้ว

    can you guide me with handle csv file upload and should be save into model and that csv may contain large data... thanks in advance

  • @satishkurakula
    @satishkurakula 2 ปีที่แล้ว

    hi what if the column names are having spaces instead of '_'(underscore) in the csv file? how should we represent the models.?

  • @user-iu4fd5ki8j
    @user-iu4fd5ki8j ปีที่แล้ว

    hi thank you for sharinbg but I am just wondering how do you make that autoifill at time 6:56 for all the coulmn in your class Book? since I trying the same methods I can not do that

  • @bayankabbani3722
    @bayankabbani3722 2 ปีที่แล้ว +1

    thanks

  • @sahithimallineni5653
    @sahithimallineni5653 2 ปีที่แล้ว

    I have executed .import something.csv library_book but I didn’t get any error but data didn’t get inserted. Is there any reason why?

  • @babycool5866
    @babycool5866 3 ปีที่แล้ว +1

    Sir, it is showing datatype mismatch what can i do pls tell me

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว

      You need to check your data in the csv matches the model data types

  • @atlasbulut4968
    @atlasbulut4968 3 ปีที่แล้ว +1

    This is great but I would like to do it on admin panel

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว +1

      Ta da...
      th-cam.com/video/BLxCnD5-Uvc/w-d-xo.html
      Its the next tutorial 👍

  • @psk9301
    @psk9301 3 ปีที่แล้ว +1

    You are best

  • @faridsa1084
    @faridsa1084 3 ปีที่แล้ว +1

    awesome

  • @hassanelabdallah5013
    @hassanelabdallah5013 3 ปีที่แล้ว

    Hello. Can you please explain annotate,alias,union and aggregate ?

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว +1

      No problem - I have done union - I think I planned aggregate tomorrow

  • @mohittamba2709
    @mohittamba2709 2 ปีที่แล้ว

    How can we import notepad file in database

  • @mukundapurtourandtravelspr6738
    @mukundapurtourandtravelspr6738 3 ปีที่แล้ว

    whenever i try to do this its showing:
    INSERT failed: attempt to write a readonly database

    • @veryacademy
      @veryacademy  3 ปีที่แล้ว +1

      Are you running Linux - check the file permission on the database - assuming you are using SQLite?

  • @datafintechsolutions
    @datafintechsolutions 10 หลายเดือนก่อน

    Valeu!

  • @zakchips
    @zakchips 3 ปีที่แล้ว

    Great.Thx.

  • @anilkumar-ug3yd
    @anilkumar-ug3yd 2 ปีที่แล้ว +1

    enitire purpose of building a model to uploaddata is ignored

    • @veryacademy
      @veryacademy  2 ปีที่แล้ว

      Thanks Anil glad to have helped.

  • @ben4571
    @ben4571 ปีที่แล้ว +1

    Why would you choose to limit the video audience scope by proceeding with an import option only available to Windows users?

    • @veryacademy
      @veryacademy  ปีที่แล้ว

      The only limits are ones that you have defined. Apologies if this was a rhetorical question.

    • @jordib.4683
      @jordib.4683 ปีที่แล้ว

      This tutorial doesn't work on Mac?

  • @ashishthaakur45
    @ashishthaakur45 3 ปีที่แล้ว

    Good one

  • @adr3wid
    @adr3wid 2 ปีที่แล้ว

    Title is misleading. It should read be "how to import CSV into SQLlite". There are a number of databases Django could be utilising. This is simply interfacing with the database, not making a ORM migration command

  • @prakashkombala
    @prakashkombala 2 ปีที่แล้ว

    Any one help me to import Json data to django model ?

  • @hamidmojarrad
    @hamidmojarrad ปีที่แล้ว

    I really expected to see you imported the csv file into sqlite using Django codes not the command line

  • @rangabharath4253
    @rangabharath4253 3 ปีที่แล้ว

    Awesome

  • @jizong234
    @jizong234 3 ปีที่แล้ว

    super claire

  • @gamingland2074
    @gamingland2074 2 ปีที่แล้ว +2

    no offense but this tutorail has nothing to do with django , it import CSV file into sqllite3 not Django Import CSV into Model

    • @veryacademy
      @veryacademy  2 ปีที่แล้ว

      No offence taken, give me a suitable title and I will replace it 👍

    • @V.D.
      @V.D. 11 หลายเดือนก่อน

      Also there is not used many-to-one relationship and because of that there is also vertical replication in a column. This is a bad practice to import data from csv