DEV Community

InterSystems Developer for InterSystems

Posted on • Originally published at community.intersystems.com

Welcome Django

With the latest improvements in support for Python in IRIS, and continued work on Python DB-API support by InterSystems. I've implemented IRIS support to the Django project where is Python DB-API is used to work with some other databases.

Let's try a simple application on Django, which stores its data in IRIS.

Image description
That application is available on

GitHub, let's clone it

git clone https://github.com/caretdev/django-iris-todo
cd django-iris-todo
Enter fullscreen mode Exit fullscreen mode

And we can build and start it with Docker-compose

docker-compose up -d --build
Enter fullscreen mode Exit fullscreen mode

It will take some some, when IRIS will be started, and Django application will catch it migrate the models there and starts application too, once it's started it will be available by http://localhost:8000/ and you should the the picture like above.

But how it works

To make it work It requires, InterSystems Python DB-API installed, it comes with the latest preview version, so, you will need to have version 2022.1.0.114.0 or above and it's located in instance's folder <INSTALL_DIR>/dev/python/. This file can also be downloaded from this GitHub repo 

pip3 install intersystems_irispython-3.2.0-py3-none-any.whl
Enter fullscreen mode Exit fullscreen mode

Django's IRIS backend is implemented by another project, and which can be installed with pip, and for sure we need django itself, let's install them

pip3 install django django-iris
Enter fullscreen mode Exit fullscreen mode

Another way to install required packages in Python is to use requirements.txt file

pip3 install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

While that file contains, this lines

https://raw.githubusercontent.com/intersystems-community/iris-driver-distribution/main/intersystems_irispython-3.2.0-py3-none-any.whl
Django~=4.0.2
django-iris~=0.1.5
Enter fullscreen mode Exit fullscreen mode

Let's connect our Django application to the IRIS, open file todoApp/settings.py

Image description

DATABASES defines connections settings to the database

ENGINE should be django_IRIS

NAME should point to Namespace in IRIS

Just change it to something, where it can connect. For instance

DATABASES = {
    'default': {
        'ENGINE': 'django_iris',
        'NAME': 'DJANGOTODO',
        'HOST': 'localhost',
        'PORT': 1972,
        'USER': '_SYSTEM',
        'PASSWORD': 'SYS',
    }
}
Enter fullscreen mode Exit fullscreen mode

And start migration

python3 manage.py migrate
Enter fullscreen mode Exit fullscreen mode

Image description

No errors, all tables on IRIS side is created

And we are ready to start our application

python3 manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Image description

Django comes with an admin panel

python3 manage.py createsuperuser
Enter fullscreen mode Exit fullscreen mode

Image description

And admin panel is available by link http://localhost:8000/admin/, 

Image description

And how it stored in IRIS

Image description

 

There are still some scope of work needs to be done to have a full support. Work still in progress for Python DB-API driver from InterSystems, and also for this django-iris project.

Be aware, that it may not work so smooth on Community Edition version, due to the way how Django connects to the database, it may use all the licenses very quickly

If you like the project, and its future impact of using IRIS please vote on OpenExchange contest

Top comments (0)