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
Close
Hashes for django_xlspopulator-1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1caf1a118b9f1ae743abb2cc3d77d7bdafea89fe7fd515db84ae341d7bfba896 |
|
MD5 | 249822dda26aad01cb01faf17ab2e626 |
|
BLAKE2b-256 | ae40705e0add97d1ce47ec322b1ad41e15daeb1b8cf8fb509c08ed60a382892d |