Automatically builds Django models from an Excel file
Project description
django-from-excel
Automatically builds Django models from an Excel file
Getting Started
The following instructions assume you already have a Django project and at least one app set up.
Installation
pip install django-from-excel
Setup
Copy the Excel file you want to convert to a location in the project that is easy to reference. The simplest approach is to place it in the same directory as manage.py
, as that is where you'll need to run the command from.
Before continuing, make sure you have created an app, and that it is registered in settings.INSTALLED_APPS
.
Add django_from_excel
to settings.INSTALLED_APPS
.
At this point, also confirm your database settings.
Run
Example:
manage.py buildfrom tracker.xlsx app --overwrite --migrate --loaddata
The following options are available for the buildfrom
command:
filename:
Required. The filename or path/to/filename for the Excel file to generate models from.
app:
Required. The app to generate models.py
and admin.py
files in. Must already exist, and must be listed in settings.INSTALLED_APPS
.
--overwrite:
Will overwrite existing admin.py
and models.py
files in the target app; otherwise, a unique hex string will be appended to the filenames, such as models_120f77f8.py
.
WARNING: If you have existing models and specify --overwrite
, they will be lost forever!
--migrate:
After generating the models, this will automatically run manage.py makemigrations
and manage.py migrate
.
--loaddata:
Once migrations are complete, this will generate a convertedmodel.json
file in <app>/fixtures
, and will then call the manage.py loaddata convertedmodel.json <app>
command.
Must be used in conjunction with --migrate
.
Inspect
View the models.py
and admin.py
files that were generated.
If you chose the --migrate
option:
Log in to the Django admin. Your converted model(s) should be listed there.
If you specified --loaddata
:
Open the model, and you should have a record for each row in the original Excel file.
Build Your Dream App
This is only intended to create a starting point. You'll want to inspect the models to make sure the field types are correct, you'll likely need to add some nullable fields or unique constraints, and you may need to spin some fields off into their own tables, with foreign keys linking back. But, hopefully django-from-excel
saved you time by quickly creating some Django models for you.
Eject
Once you are satisfied with the results, you can remove django_from_excel
from settings.INSTALLED_APPS
and uninstall django-from-excel
and any other dependencies you don't need for your project.
TODO's
- Detect nullable data by columns with blank cells, while maintaining ability to detect column's data type
- Detect duplicate data that should be in a foreign table, and create corresponding ForeignKey field
- Create an eject command
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
Hashes for django_from_excel-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb167ed91b2658e72f07be4876f469f620fcafde0c9163661d138d23462828f6 |
|
MD5 | 4d7075d7b444c1606f50b5908cee75c6 |
|
BLAKE2b-256 | 7c40752640c3fb6aabeb90f67525c3d11807960192ea2e51e59052f0efd5ece6 |