Code Monkey home page Code Monkey logo

Comments (3)

chfw avatar chfw commented on June 23, 2024

Hi, Joseph

What I understood your intention is to insert some custom data from your form during the file import, whereas the tutorial shows only database import without 'salt'.

One idea is take advantage of row initializer to do custom change. The other idea is to use get_sheet( get_book )to obtain the pyexcel.Sheet( pyexcel.Book) instance, with which you can do data manipulations. Then you can use pyexcel.Sheet.save_to_django_model ( pyexcel.Book.save_to_django_models ) for the data import.

Hope it helps.

Chfw

from django-excel.

jsartre avatar jsartre commented on June 23, 2024

Hi Jaska,

Thank you for your answer. Yes you are correct, for every row that is imported, I would like to set one specific field.

For example:
if I have three columns in the excel file [number, name, address] I would like to set the extra field account_id in the database. All the rows ill have the same account_id.

I was trying to look at the first option that you proposed : initializer. However, I am exactly sure how to use this method. Should I pass a query? or just a specific parameter?

Thanks in advance.

Joseph

from django-excel.

chfw avatar chfw commented on June 23, 2024

Under the first route, the initializer is expected to return a list of values for each new row/data entry, which is in the same order as the column_names.

The default assumption is that the number of column names matches the number of data columns and their order is the same. Your use case is, the 4th column is outside the spreadsheet.

Recommended route is to go with the second one: get a sheet out, populate 4th column and save to django model.

Hacking route is via first route, set column_names = [number, name, address, account_id](note, account_id should be the exact database field name), then in your row initializer, add: row.append(the_same_account_id_for_all), which append a 4th item onto the row. This could work out too.

from django-excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.