Comments (3)
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.
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.
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)
- Save to model.FileField a generated xls
- How dow I format individual fields from a queryset in a make_response_from_querysets HOT 1
- How do I ignore a row or column when import data use save_to_database? HOT 2
- Incorrect message on file not found HOT 2
- Doc in Chinese HOT 1
- Unable save table after making changes in the model.py file HOT 1
- Question: How to overwrite the default encoding HOT 3
- Exception Type: IntegrityError Exception Value: UNIQUE constraint failed: myapp_question.slug HOT 2
- Not able to upload large excel or CSV file with the size 10Mb
- Urgent Help: Trying to Import data from two sheets(xlsx) into two different models(Foreign Key Related) - Not able to lead the Data HOT 5
- build failed with django 3.1.1 HOT 8
- jump column HOT 3
- Unable to support XLS and XLSX uploads in Python 3.9 HOT 3
- start test got wrong HOT 2
- Can't get XLSX support working HOT 4
- Import related models without static foreign keys HOT 4
- How to create an import for whole document without defining 'choice' and 'question'?
- Realy? Object of type UUID is not JSON serializable HOT 2
- Django 4.0 forward compatibility Error HOT 1
- <ul class="errorlist"><li>This field is required.</li></ul>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-excel.