- April 22, 2020
Flask, Python, ...
First and foremost: this : https://flask-sqlalchemy.palletsprojects.com/en/2.x/ This is the old Flask website built in flask. Some patterns are outdated. But still pretty nice to gloss over with a cup of tea and some buiscuits. 🙂 https://github.com/pallets/flask-website/tree/master/flask_website scoped_session(sessionmaker()) or plain sessionmaker() ? Well, the recommended pattern is to use scoped_session as it is considered thread safe. […]
I was trying to install psycopg2 database adapter for PostgreSQL on Ubuntu 18.04. And was always getting an error when doing “pipenv install psycopg2”, complaining about “Python.h” missing. After much head-scratching, I found the issue. Multiple Python distributions confuse psycopg2 installation. Its like this. psycopg2 has two main dependencies libpq-dev python3-dev. On Ubuntu, you install […]
- April 19, 2020
Flask, PyCharm, ...
Setup Environment 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 […]
This describes the basic overview of SQL Alchemy. Notice the color theme. It will be related to the next onion-ring overview of SQL Alchemy. SQL Alchemy is divided into Core and ORM. You can use Core and not use ORM. ORM is more geared towards mapping model objects to Python data types. Core on the […]
- April 12, 2020
Schema PostgreSQL Schema: Exactly like namespaces in SQL Server (dbo in SQL Server is equivalent to public in PostgreSQL. The default namespace.) Logical container of tables and other database objects You can have multiple schemas in a database Schemas (or namespaces) are useful in production environment in that we can assign users to them and […]
- April 11, 2020
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 […]
- April 10, 2020
Flask, Python, ...
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 […]
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 […]
- March 10, 2020
Back End Development, Django, ...
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 […]
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 […]