CSV to API#
This page explains how to convert a CSV File into a Secure API 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.zip
cd dynamic-django
The project set up is the usual one for any Django 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 Model#
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.
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 CSV file integrity
python manage.py csv-to-model -f Titanic.csv # STEP #3: Generate the Model
python manage.py makemigrations # STEP #4: Generate Migration SQL
python manage.py migrate # STEP #5: Apply Changes in DataBase
python manage.py csv-to-model -f Titanic.csv -l # STEP #6: (Optional) Load Data
At this point, we have the CSV file translated into a DataBase model and the information loaded (if the last step was executed)
Explanation of the steps#
STEP #1: Print the tool help information using -i argument
STEP #2: Check the integrity of the Titanic.csv, saved in the media directory located in the root of the project
STEP #3: Translate the CSV file to a Django model. The generated Python code is added to the home/models.py file
STEP #4: Execute makemigrations command that generates the SQL code for DB migration
STEP #5: Apply the Database migration
STEP #6: Loads the content of the CSV file into the generated model
Configuration Update#
To activate a secure API Enpoint for the new model, we need to edit the project configuration as suggested below.
# Syntax: URI -> Import_PATH
DYNAMIC_API = {
"product": "home.models.Product",
"sales": "home.models.Sales",
"titanic": "home.models.Titanic", # <-- NEW
}
The new endpoint is now listed in the Dynamic API 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