Django Sage Painless

The django-sage-painless is a valuable package based on Django Web Framework & Django Rest Framework for high-level and rapid web development. The introduced package generates Django applications. After completing many projects, we concluded that any basic project and essential part is its database structure. You can give the database schema in this package and get some parts of the Django application, such as API, models, admin, signals, model cache, setting configuration, mixins, etc. All of these capabilities come with a unit test. So you no longer have to worry about the simple parts of Django, and now you can write your advanced services in Django. The django-sage-painless dramatically speeds up the initial development of your projects. Documentation of this package is available in readthedocs.

Project Detail

  • Language: Python > 3.6
  • Framework: Django > 3.1

Git Rules

S.A.G.E. team Git Rules Policy is available here:

Getting Started

Before creating Djagno project you must first create virtualenv.

$ python3.9 -m pip install virtualenv
$ python3.9 -m virtualenv venv

To activate virtualenvironment in ubuntu:

$ source venv/bin/activate

To deactive vritualenvironment use:

$ deactivate

Start Project

First create a Django project

$ mkdir GeneratorTutorials
$ cd GeneratorTutorials
$ django-admin startproject kernel .

Install Generator

First install package

$ pip install django-sage-painless

Then add 'sage_painless' to INSTALLED_APPS in

TIP: You do not need to install the following packages unless you request to automatically generate an API or API documentation.

However, you can add following apps in your INSTALLED_APPS:

  • 'rest_framework'

  • 'drf_yasg'

  • 'django_seed'



To generate a Django app you just need a diagram in JSON format. diagram is a json file that contains information about database tables.

Diagram examples

start to generate (it is required for development. you will run tests on this app)

First validate your diagram format. It will raise errors if your diagram format is incorrect.

$ python validate_diagram --diagram <path to diagram>

Now you can generate code

$ python generate --diagram <path to diagram>

Here system will ask you what you want to generate for your app.

If you generated api you have to add app urls to

urlpatterns = [
  path('api/', include('products.api.urls')),
  • You have to migrate your new models

    $ python makemigrations
    $ python migrate

  • You can run tests for your app

    $ python test products

  • Django run server

    $ python runserver

  • Rest API documentation is available at localhost:8000/api/doc/

  • For support Rest API doc add this part to your

    from rest_framework.permissions import AllowAny
    from drf_yasg.views import get_schema_view
    from drf_yasg import openapi

    schema_view = get_schema_view(
    title="Rest API Doc",
    description="Auto Generated API Docs",
    license=openapi.License(name="S.A.G.E License"),

    urlpatterns = [
    path('api/doc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-swagger-ui'),

  • Rest API documentation is available at localhost:8000/api/doc/

How to Contribute

Run project tests before starting to develop

  • products app is required for running tests

    $ python startapp products


  • you have to generate everything for this app

  • diagram file is available here: Diagram

    $ python generate --diagram sage_painless/tests/diagrams/product_diagram.json

  • run tests

    $ python test sage_painless