Metadata-Version: 2.1
Name: djdynatable
Version: 1.0.4
Author: Anand Raj
Author-email: anand98.ar@gmail.com
License: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Education
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# 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 .

##### **refer** : https://docs.djangoproject.com/en/5.0/ref/schema-editor/

## Authors

- [@anandrajB](https://github.com/anandrajB)

## Prerequisite

- python
- Django
- Django-rest-framework

## 1. Installation

### 1.1 Initial setup

- Install djdynatable using [pip](https://pypi.org/project/djdynatable/)

```bash

pip install djdynatable

```

- In your django application , browse to installed_apps section in settings.py and add this ,

```bash

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](https://django-tenants.readthedocs.io/en/latest/install.html#basic-settings)


- 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

- [link1](https://documenter.getpostman.com/view/11858287/2sA3QqhYYp)

- [link_2](https://github.com/anandrajB/django-dynamic-table/blob/main/package/body_data.md)
