Populate your Django model from .xls file
Project description
django_xlspopulator
Easy to use .xls Django model populator.
How to:
- First you need to install latest version of xlrd: pip install xlrd==1.1.0
- In order for this to work, you need exactly match your model's field names and xls's first row values(column names), like this:
class Test(models.Model): one = models.CharField(max_length=150) two = models.CharField(max_length=150) three = models.CharField(max_length=150) four = models.CharField(max_length=150)
- Then you need to create
populate.py
file at the one level with yourmanage.py
- Put following code there:
# populate.py import os import django from django_xlspopulator.populator import Populator os.environ.setdefault('DJANGO_SETTINGS_MODULE','YOURPOJECT.settings') django.setup() from YOURAPP.models import Test pop = Populator('C:/Users/Guido/Desktop/testfile.xls', Test) pop.populate()
- Populator object takes three arguments:
- path to the .xls file in form of a string
- Django model object
- Sheet number, int(0 by defaulft, specify it if you want to use other sheet)
- Populator object takes three arguments:
- Run
populate.py
from the terminal and wait. For my old machine with SQLite it took 5 mins to populate model from file that had 4 columns and 10000 rows.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_xlspopulator-1.1.tar.gz
.
File metadata
- Download URL: django_xlspopulator-1.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
570bbf79a422b40a7fe4f4a791ed6117b79320c7adc027309a1129f5445154f3
|
|
MD5 |
b7c071dee8e91fba73299b81e75dfcfd
|
|
BLAKE2b-256 |
3b8f61e66aa2097e4429b19d00a1ffaf95f91bf8906bef09f7892544359480dd
|
File details
Details for the file django_xlspopulator-1.1-py3-none-any.whl
.
File metadata
- Download URL: django_xlspopulator-1.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
1caf1a118b9f1ae743abb2cc3d77d7bdafea89fe7fd515db84ae341d7bfba896
|
|
MD5 |
249822dda26aad01cb01faf17ab2e626
|
|
BLAKE2b-256 |
ae40705e0add97d1ce47ec322b1ad41e15daeb1b8cf8fb509c08ed60a382892d
|