Blog


PostgreSQL installation and configuration on ubuntu 18.04

Installation: Bad way First install postgress from ubuntu repos (note: this will lag behind the latest version directly from postgreSQL official page but far easier to install and uninstall). sudo apt update sudo apt install postgresql postgresql-contrib Installation complete. contrib package contains additional postgres utilities. Installation: Latest Version : Right Way Create the file /etc/apt/sources.list.d/pgdg.list […]




Basic Rest API in Flask and SqlAlchemy

Step 1: pipenv install –python 3.8 Step 2: pipenv shell Step 3: pipenv install flask flask-sqlalchemy flask-marshmallow marshmallow-sqlalchemy flask-migrate psycopg2 flask-sqlalchemy is the sql-alchemy with flask bindings. flask-marshmallow is like the Serializer in Django Rest Framework, marshmallow-sqlalchemy is common binding between marshmallow and sqlalchemy (for things like ModelSerializer in Django Rest Framework).flask-migrate is migration tool […]




Django and Django Rest Framework Permissioning system

What are Permissions In Django Permissions can apply to Individual Users Groups of Users Permissions are all about Access – Who can see what? Control – Who can do what In django docs, Permissions are defined like so: Permissions [are] binary (yes/no) flags designating whether a user may perform a certain task So, the above […]




Django celery + rabbitmq + redis: Use rabbitmq as broker and redis as results backend

Celery is a task queue with focus on real-time processing, while also supporting task scheduling. RabbitMQ is a message broker. This means it handles the queue of “messages” between Django and Celery. Redis is a key-value based storage (REmote DIstributed Storage). Very fast. Used for results backend. Code for this tutorial is here: https://github.com/tek-shinobi/celeryDj Install […]




Django TDD setup

Unit Tests Setup 1. Create virtual env. pipenv shell 2. Install django pipenv install django 3. Create django project. django-admin startproject tested 4. Create .gitignore file touch .gitignore settings setup a settings file for tests. This will use an in-memory sqlite DB (sqlite3). This is good because we don’t want a PG or MySQL db […]




Python Descriptors

Descriptors are often overlooked part of Python. We are all aware of @property. Descriptors are what power it. So lets take a look at them. Why Descriptors Look at this code: class Person: def __init__(self, name): self._name = name @property def name(self): return self._name.capitalize() @name.setter def name(self, value): self._name = value @name.deleter def name(self): del […]




Mixins in Django and Django Rest Framework

This is a general post about what mixins are. Mixins are a design pattern found in many languages. In Python, though the language does not support mixins natively,they are implemented using Python’s multiple inheritence model. The mixins are different from inheritence. Inheritence is useful when you want to narrow a scope in the inherited class. […]




Using Pytest with Django and Django Rest Framework

This article is inspired by article here. What is Pytest Pytest is testing framework for Python. Very popular with Django. Killer feature : Fixtures Fixtures are the killer feature of Pytest. Fixtures are functions that run before and after each test, like setUp and tearDown in unitest and labelled pytest killer feature. Fixtures are used […]




Python: Bare asterisk in function arguments?




Adding Custom User model in Django – part 2 (using fixtures)

See part 1 here. In this part we are discussing what to do when we add custom user model later in the project. Note that in this scenario, we are in a very non-ideal situation. To keep unknown surprises at the minimum, we will still delete old database but we will use the concept of […]