Skip to content

anandrajB/django-dynamic-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Django Dynamic Table

  • The djdynatable library provides a convenient and flexible way to work with dynamic tables in your Django application. It allows you to create tables programmatically, add columns, modify existing tables, and perform other operations without the need for complex migrations or model definitions. However you can create tables on-the-fly based on user input or other dynamic factors.

  • With added django-tenants you can add custom schema whereas your tables will be created in that schemas rather than public schemas in your postgres db .

Authors

Prerequisite

  • python
  • Django
  • Django-rest-framework

1. Installation

1.1 Initial setup

  • Install djdynatable using pip
pip install djdynatable
  • In your django application , browse to installed_apps section in settings.py and add this ,
INSTALLED_APPS = [
    'djdynatable',
    'rest_framework'
]
  • Now add urls in urls.py

urlpatterns = [

    path('', include('djdynatable.urls'))

]

1.2 Migrations

  • once all the steps done from the above section 1.1 .
  • now we can apply the migrations for the database using ,

- python manage.py makemigrations


- python manage.py migrate 

2. Setup (without django-tenants)

  • by default the public schema will be selected

  • navigate to api/table/

  • To set up a new dynamic table, send a POST request to api/table/ with the following body data:

{
   "tblname":"customer_details",
   "columns":[
      {
         "colname":"username",
         "coltype":"string"
      },
      {
         "colname":"phone_number",
         "coltype":"number"
      }
   ]
}
  • now in your pgadmin under public schema , check that the new table will be created dynamically with 2 columns as id, username , phone_number , without any migrations

  • with rest of the api's your can dynamically add , drop , modify columns and rows as per your need .

2.1 . Setup (with django-tenants)

  • make sure you completed the basic setup instructions mentioned in the django-tenants documenatation , for more info check here

  • now navigate to api/table

  • now the table creation post api need to called with same body data , the new schema will be created in your postgres db in that the dynamic tables will be created

for more information check the api documentation

About

A lightweight Django SDK to create tables and rows dynamically

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages