CSV to DB Table#

This page explains how to translate a CSV File into a DataBase Table using Dynamic Django tool.

👉 New to App-Generator? Join our 10k+ Community using GitHub One-Click SignIN.

Download Dynamic Django#

For newcomers, Dynamic Django is a commercial tool that aims to simplify the data processing and consolidation via generated APIs, DataTables, Charts and CLI tools.

To get the product navigate to the payment page and complete the purchase. Unpack the ZIP archive and folow these steps:

Unzip Dynamic Django#
unzip dynamic-django.zip
cd dynamic-django

The project set up is the usual one for any Django project:

Start the project#
virtualenv env                    # create a virtual environment
source env/bin/activate           # activate VENV
pip install -r requirements.txt   # install modules
python manage.py makemigrations   # migrate DB
python manage.py migrate          # apply changes
python manage.py runserver        # start Dynamic Django tool

At this point, we can visit the tool in the browser at localhost:8000.

Convert CVS into a Table#

Once the tool is properly installed, the next step is to execute csv-to-model custom command to process the CSV file. Here are the steps for Titanic.csv file, shipped with the tool.

Convert the CSV to a DB Table#
python manage.py csv-to-model -i                # STEP #1: Print the help
python manage.py csv-to-model -f Titanic.csv -c # STEP #2: Check File integrity
python manage.py csv-to-model -f Titanic.csv    # STEP #3: Generate the model definition
python manage.py makemigrations                 # STEP #4: Generate Migration SQL
python manage.py migrate                        # STEP #5: Apply Changes in DataBase

At this point, we have the CSV file translated into a DataBase Model/Table ready to be used.

Explanation of the steps#

  • STEP #1: Print the tool help using -i argument

  • STEP #2: Check the integrity of the CSV file using -c argument

  • STEP #3: Translate the CSV file to a Django model. The definition is also printed in the terminal

  • STEP #4: Execute makemigrations command that generates the SQL code for DB migration

  • STEP #5: Apply the Database migration

Invoke the Model (Django Shell)#

The model can be used and provisioned with information using python manage.py csv-to-model -f Titanic.csv -l command. Please note the -l argument that enables the data load.

Access the new Model#
python manage.py shell

>>> from home.models import *
>>> Titanic.objects.all()
<QuerySet []>

Video Resources#

This video material explains how to process CSV files and convert them into secure APIs and server-side data tables using Dynamic Django tool.