Fast start application Django

Jane Ratthanan
2 min readApr 19, 2021

Project Structure

├── django/
├── [project_name]/
├── apps/
├── [app1_name]
├── admin.py
├── apps.py
├── models.py
├── serializers.py
└── views.py
├── setting.py
├── api_urls.py
├── manage.py
├── scripts/
├── startapp.sh
├── generate.sh
  1. Create a directory for storing the script.
mkdir scripts && cd scripts

2. Create startapp.sh to create an application in the project.

touch startapp.sh

3. Install drf-generators and follow the Installation of a document

$ pip install drf-generators

To use DRF Generators, add your INSTALLED_APPS.

INSTALLED_APPS = (
...
'rest_framework',
'drf_generators',
...
)

4. Create generate.sh to generate serializers.py and views.py for your application.

5. Try creating a new application by run the command startapp.sh

$ bash scripts/startapp.sh <app name>

6. Writing model your new application.

in settings.pyLOCAL_APPS = [
...
'main.apps.products',
]

and run python manage.py makemigrations && python manage.py migrate then new file migration.

7. run the command generate.sh

$ bash scripts/generate.sh <app name>

8. Add Viewset in api_urls.py

from main.apps.products.views import ProductViewSet


router = DefaultRouter()
app_name = 'api_urls'

# Register your API router here. It should be sorted by alphabet

router.register('products', ProductViewSet)

9. Finally. I get it.

--

--