How to create objects in the Django database from a CSV file upload

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 73

  • @jeffreypowell2723
    @jeffreypowell2723 3 года назад +6

    This is by far the best and most complete explanation of importing csvs to a database in django. I also appreciate other videos from the same person.

    • @Pyplane
      @Pyplane  3 года назад +1

      Thank you Jeffrey! :)

  • @adelabu-ghazaleh1228
    @adelabu-ghazaleh1228 3 года назад

    Thank you. It works perfect, while when the load is large you need to use window.location.href = url
    and prevent the default behavior of redirection of the form using Iframe:
    ...

  • @santiagoagulla7826
    @santiagoagulla7826 2 года назад

    My guy you saved me. Thank you so much!

    • @Pyplane
      @Pyplane  2 года назад

      Thanks for watching! 💪

  • @mayurg2661
    @mayurg2661 4 года назад +2

    really awesome tutorial! i tried other ones but none of them worked for csv. Nicely taught!

    • @Pyplane
      @Pyplane  4 года назад +1

      Thank you Mayur! Very happy you enjoyed it :)

  • @elysetombojara3183
    @elysetombojara3183 3 года назад

    Thank you so much my friend. This course help me more to practice Django.I will follow your channel

  • @haileeisabella6481
    @haileeisabella6481 3 года назад

    this just saved my computer science coursework, thank you!!!

    • @Pyplane
      @Pyplane  3 года назад

      Thank you for this comment :) glad my video helped you out! Cheers!

  • @ericcantona9443
    @ericcantona9443 2 года назад

    Thanks man, it was so helpful

  • @ryanbowns1517
    @ryanbowns1517 Год назад

    Great Job on this !

  • @edcyn5832
    @edcyn5832 4 года назад +1

    Thanks for wonderful tutorial. I just smashed the subscribed button!

    • @Pyplane
      @Pyplane  4 года назад

      Awesome :) thanks!

  • @mitaakter4627
    @mitaakter4627 2 года назад

    sir thank you very much for your tutorial.

    • @Pyplane
      @Pyplane  2 года назад

      Thanks for watching! :)

  • @jennykow3777
    @jennykow3777 3 года назад +1

    Nice tutorial, thanks a lot! Very professional :) Greetings from Warsaw ;)

  • @thetruereality2
    @thetruereality2 2 года назад

    Very good idea, thank you for sharing.

  • @eesakamaldien1917
    @eesakamaldien1917 2 года назад

    Hi this video is amazing but I am using another model instead of user, so how would I do this with another model as the foreign key. Please help and thanks in advance. subscribed!

  • @alexdin1565
    @alexdin1565 2 года назад

    thanks you are the best

  • @DemolaOkesola
    @DemolaOkesola 3 года назад

    💯 You're the man! Well Explained.

  • @MrValVet
    @MrValVet Год назад

    On 30:40, there"s a media folder in the project folder where sales_data.csv gets saved. I can"t find this folder in my project directory. What am I missing? (BTW, the csv file does get uploaded to that folder, but I can"t find it on my file system). Suggestions?

  • @rezasadeghi2520
    @rezasadeghi2520 3 года назад +1

    loving this!

  • @satishkurakula
    @satishkurakula 3 года назад

    Thank you very much @pyplane

    • @Pyplane
      @Pyplane  3 года назад

      thanks for watching:) Cheers!

  • @1MoreNaturalDisaster
    @1MoreNaturalDisaster 3 года назад +1

    How do you keep duplicates out when importing a .CSV file?

  • @venkyslarky8817
    @venkyslarky8817 2 года назад

    How can we add some logic to avoid duplicate entries for the incoming data. For example I am able to save the excel file in my database using to_sql. I have to validate that no two duplicate entries can be created for a column in this case I have title column and validate if two products have same title or name, the entry does not get added to the database.

  • @chuckli1149
    @chuckli1149 3 года назад

    thank you for the tutorial! It works great!!

  • @zayed868
    @zayed868 3 года назад

    Good Job.

  • @righteousEarth
    @righteousEarth Год назад

    its very informative.. but how to get "date" types ..apparently it cannot open date type now..anybody knows?

  • @chia-hunglee4970
    @chia-hunglee4970 4 года назад

    Hi, thanks for the nice vedio. I try to follow your instruction and run into a problem at the very end, it pops out "unsupported operand type(s) for *: 'NoneType' and 'int' " Can you provide me some suggestions to deal with it?

  • @bijoysaraf650
    @bijoysaraf650 4 года назад +1

    Well summarized tutorial on importing csv to DRF API. This was very helpful.
    Is there a way you can do multiple csv files contents import one after another?
    That would a nice thing to know.
    Thank you for sharing. Already liked and subscribed for a while now!

    • @Pyplane
      @Pyplane  4 года назад

      Hi Bijoy. Thanks for the nice words. Regarding your question... if you keep the files in one directory you could probably loop through them and read their content

    • @Pyplane
      @Pyplane  4 года назад

      On my blog you can find a hint how to do that with this article: blog.pyplane.com/blog/pandas-analysis-concat-multiple-csv-files/

  • @eesakamaldien1917
    @eesakamaldien1917 2 года назад

    hi it was working while testing locally but once i deployed the app it says expected byte or byte array and not strings please help!

  • @MA-ek1xl
    @MA-ek1xl 2 года назад

    kept getting "multiple objects Returned at/" when using the Csv.objects.get() method. Would've used filter, but didn't know what to filter on because all the csv's were the same.

  • @rezasadeghi2520
    @rezasadeghi2520 3 года назад

    Hi Luke
    How do you create an object from a csv file when there is a foreign key or many to many relationship between two classes ?

    • @eesakamaldien1917
      @eesakamaldien1917 2 года назад

      Hi have you solved this issue?

    • @rezasadeghi2520
      @rezasadeghi2520 2 года назад

      @@eesakamaldien1917 not yet

    • @eesakamaldien1917
      @eesakamaldien1917 2 года назад

      @@rezasadeghi2520 hi is solved issue, let me know if you still having issue

    • @denisjs4
      @denisjs4 2 года назад

      ​@@eesakamaldien1917 Hello. Can you provide me with a solution? I need it very much. Thank you

    • @eesakamaldien1917
      @eesakamaldien1917 2 года назад

      @@denisjs4 yes I can provide solution, will shortly

  • @OMPRAKASH-uz8jw
    @OMPRAKASH-uz8jw Год назад

    bro, teach us how can we do it from the front end

  • @jameskulu
    @jameskulu 3 года назад

    How can we send that csv file from one function to another ?

  • @harshamachine_learning7831
    @harshamachine_learning7831 4 года назад

    so can we create a table for every csv file upload we make ?

  • @swapnilpandharpatte9446
    @swapnilpandharpatte9446 3 года назад

    sir i have imported all of the module which are used in project it shows syntax erro
    r

  • @joelee9313
    @joelee9313 4 года назад

    hello,great video, I had a question, i got my file in /media/ folder but i couldn't see it on my admin page, would you pls help me pls ?

    • @Pyplane
      @Pyplane  4 года назад +1

      Hi Joel. Did you configure media files in the settings.py and did you include them in the url patterns?

    • @joelee9313
      @joelee9313 4 года назад

      @@Pyplane I didn't mention clearly, sorry. I uploaded the file through upload.html. I could see the file in my media folder which means the upload was successful. But I couldn't see the file in my admin page.

    • @Pyplane
      @Pyplane  4 года назад

      and dod you include media files in the url patterns?

    • @joelee9313
      @joelee9313 4 года назад

      sorry, yes , I add media_url and media_root and import setting and add that sentence after the url_pattern in urls.py

    • @joelee9313
      @joelee9313 4 года назад

      thank you for helping me, I will watch your video again and compare what I did wrong with my code. Thank you, That's very kind of you.

  • @KingKong-zq4mp
    @KingKong-zq4mp 3 года назад

    Did exactly the way the tutorial is, but CSRF token missing or incorrect is being shown.

  • @I2W
    @I2W 3 года назад

    Hi, I need some help
    It seems that MultipleObjectsReturned error was shown, How do I fix this

  • @PP-tc1zp
    @PP-tc1zp 3 года назад +2

    Hi guys,
    I have problem with running this
    I have: '''IndexError: list index out of range''' or errors with types(float, int, None)

  • @mayankgarg8103
    @mayankgarg8103 Год назад

    I am getting an error
    django.core.exceptions.FieldError: Unknown fields (filename) specified for Csv. Can anyone tell why such error is occuring?
    This error is related to forms.py of csvs folder in the class CsvModelForm

  • @pabloespin
    @pabloespin 2 года назад

    Hello everyone!. does anybody knows how to upload images if the path is giving in the csv file. Thank you

  • @balasubramanian8520
    @balasubramanian8520 2 года назад

    Can I get this git hub like for this

  • @Powiratel
    @Powiratel 3 года назад

    nice!hope it's can help me with my task.And why don't you use Pycharm? Just for some notice:it's free if using jetbrains-agent.jar

  • @LookNumber9
    @LookNumber9 3 года назад

    I'm getting a Sale() got an unexpected keyword argument 'salesman' error. Not sure why. Everything else was working.

  • @pixel7038
    @pixel7038 3 года назад

    is_valid function inside of csvs/views.py keeps returning false....what am I doing wrong?

    • @pixel7038
      @pixel7038 3 года назад

      raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__)

  • @tawhidshaheed145
    @tawhidshaheed145 4 года назад

    I want to upload a file and parse mail ID from that file. After that, those(mail ID) will be saved in my database. I tried with this code bellow and got this error. Here is my views.py and model.py file
    Please somebody help me out :(

  • @muhammadrizal3624
    @muhammadrizal3624 4 года назад

    I get an error, can I get the full source code in this video?

    • @Pyplane
      @Pyplane  4 года назад +2

      Hi Muhammad. I will do the uploads of at least main projects to github probably next week.

  • @christophermsb
    @christophermsb 3 года назад

    First, I would like to point out the the "Sales data file download" link in your description is broken. In addition to that, I have followed along almost to the end but when I click on confirm the CSV isn't uploaded. I can see no reason why it wouldn't be. My code is almost identical to yours. I am on a windows machine and so I used a different package for obtaining the path but it works just fine with the html templates. I am not sure what the heck is going on. I was hoping I could download your code and go through it line by line but, as I said before, the link is broken. Unfortunate...

    • @christophermsb
      @christophermsb 3 года назад

      Just as a little FYI, I found the error in my code. After putting in some "Print()" statements I was able to track it down. What was happening was my form was coming up blank and therefore invalid. The reason for this was that in my uploads.html file I had "mothod="post"" instead of "method="post". You see, this is why non-compiled code. A compiler would have never let that typo slide. /sigh Took freakin hours to find.