Importing file from shell
See original GitHub issueI didn’t find anything on that nor in the documentation neither in the source, so I’m currently trying with this code:
from import_export.admin import ImportMixin
from yourapp.models import SomeModelResource
filename='/home/user/filename.csv'
format_number = 0 # CSV
resource = SomeModelResource()
mixin = ImportMixin()
input_format = mixin.get_import_formats()[format_number]()
tmp_storage = mixin.get_tmp_storage_class()(name=filename)
dataset = input_format.create_dataset(tmp_storage.read(input_format.get_read_mode()))
resource.import_data(dataset, dry_run=False, raise_errors=True, file_name=filename)
tmp_storage.remove()
Is there a preferred way to do this? Did I miss it somewhere? Because I’m losing all my RAM + 1G of swap to the confirmation page on a big import. And I don’t think that splitting the file and feeding chunks one by one is an adequate workaround.
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (11 by maintainers)
Top Results From Across the Web
Import / Source Files in Bash | dave eddy
Importing files in Bash is a way to take a bash file, and implant (import) it in another script temporarily during runtime.
Read more >Import a local bash file into another bash file - Stack Overflow
Read and execute commands from FILENAME in the current shell. The entries in $PATH are used to find the directory containing FILENAME.
Read more >importing data from a text file to a bash script
Here are two solutions: Importing data from an external file into a Bash script: Read the file and store its contents as entries...
Read more >import command in Linux with Examples - GeeksforGeeks
import command in Linux system is used for capturing a screenshot for any of the active pages we have and it gives the...
Read more >Import functions and variables into Bash with the source ...
You can use source to "import" a file into your shell environment, just as you might use the include keyword in C or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A PR with tests would be good
A management command would be great.