CSV to DataTable#
This page explains how to convert a CSV File into a powerfull Server-Side DataTable using Dynamic Django tool.
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 to DataTable#
Once the tool is properly installed, we need to use the 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 # STEP #2: Generate the Model python manage.py makemigrations # STEP #3: Generate Migration SQL python manage.py migrate # STEP #4: Apply Changes in DataBase python manage.py csv-to-model -f Titanic.csv -l # STEP #5: Load Data into DataBase
At this point, we have the CSV file translated into a DataBase model and the information loaded
Explanation of the steps#
STEP #1: Print the tool help information using -i argument
STEP #2: Translate the CSV file to a Django Model. The generated Python code is saved in home/models.py file
STEP #3: Execute makemigrations command that generates the SQL code for DB migration
STEP #4: Apply the Database migration
STEP #5: Loads the content of the CSV file into the generated model
Configuration Update#
To activate the Dynamic DataTable for the new model, we need to edit the project configuration as suggested below.
Edit Configuration: Activate Dynamic API for the generated model#
# Syntax: URI -> Import_PATH DYNAMIC_DATATB = { "product": "home.models.Product", "sales": "home.models.Sales", "titanic": "home.models.Titanic", # <-- NEW }
The new endpoint is now listed in the Dynamic DataTable index page and ready to be used: http://localhost:8000/api/titanic/
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.
Links#
👉 New to App-Generator? Join our 10k+ Community using GitHub One-Click SignIN.
👉 Download products and start fast a new project
👉 Bootstrap your startUp, MVP or Legacy project with a custom development sprint