0

I’m working on my first Django project and I have hit a wall on trying to import data into an application.

My model is (roughly)

  • Vendor
    • contract (pk is in Vendor)
      • pricelist items (several rows of items - pk is in contract)

My goal is to have a form field in the admin that allows me to upload a csv file (formatted to follow the pricelist model) and overwrite the content of that model in relation to the pk in the contract model. In the admin I have set up the form for creating a vendor, contract and have manual input of pricelist items - however I can’t figure out how to populate the pricelist items from a csv file.

What would be the easiest (and hopefully correct way) of going about that?

I have looked at the django-adaptors project, but honestly the documentation for that doesn’t make much sense (I think), and I have look on quite a few github project hoping to find a similar project I could be inspired by

Peter B
  • 59
  • 1
  • 7
  • 1
    check out: http://stackoverflow.com/questions/3974620/import-csv-data-into-database-in-django-admin – saurcery Mar 20 '13 at 06:51
  • I know you can add "actions" to Django Admin, as you can see in [Admin actions in Django documentation](https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/). Maybe you can create a custom action that provides intermediate pages, where your page would be a "Select file to upload" page. – DMunoz Mar 24 '13 at 19:37
  • @syqlo I managed to get the bulk create working based on the other question you linked to. Now I just need to find a way to bulk delete pricelist_items when uploading a new pricelist - any ideas on how to do that? – Peter B Apr 12 '13 at 11:26

0 Answers0