Links: PROGRAMMING - PYTHON
Rel: python 3rd party packages
Ref: docs
- django-import-export
- django-tables2
- django-filter
- django-crispy-forms
Tags: #public

Django (web framework)

pip install Django


django-admin startproject projname
django-admin startapp appname
python manage.py # ... {: id="..." }

fixtures

https://docs.djangoproject.com/en/3.2/howto/initial-data/


I don't need any of the sites actually, rather, I need to dissect -> a single django mysite:

tsite
django-nested-admin
psycopg2

mysite
django-tinymce

fitsite
django-crispy-forms

django-admin startproject projname
python manage.py migrate
django-admin startapp appname

from django.shortcuts import render

def about(request):
    return render(request, 'base/about.html')

~=

from django.views.generic import TemplateView

urlpatterns = [
    path('', TemplateView.as_view(template_name='base/about.html')),
]

dj snippits


django recieve webhooks

asgi.py

"""
ASGI config for tutorial project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
[https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/](https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/)
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings')

application = get_asgi_application()

wsgi.py

"""
WSGI config for tutorial project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
[https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/](https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/)
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings')

application = get_wsgi_application()

admin.py

from django.contrib import admin

# Register your models here. {: id="register-your-models-here." }

apps.py

from django.apps import AppConfig


class SnippetsConfig(AppConfig):
    name = 'snippets'

models.py

from django.db import models
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles

LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted([(item, item) for item in get_all_styles()])


class Snippet(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=False)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)

    class Meta:
        ordering = ['created']

views.py

from django.shortcuts import render

# Create your views here. {: id="create-your-views-here." }

urls.py

"""tutorial URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    [https://docs.djangoproject.com/en/3.1/topics/http/urls/](https://docs.djangoproject.com/en/3.1/topics/http/urls/)
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
]

tests.py

from django.test import TestCase

# Create your tests here. {: id="create-your-tests-here." }

serializers.py

from rest_framework import serializers
from snippets.models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES


class SnippetSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    title = serializers.CharField(required=False, allow_blank=True, max_length=100)
    code = serializers.CharField(style={'base_template': 'textarea.html'})
    linenos = serializers.BooleanField(required=False)
    language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, default='python')
    style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly')

    def create(self, validated_data):
        """
        Create and return a new `Snippet` instance, given the validated data.
        """
        return Snippet.objects.create(**validated_data)

    def update(self, instance, validated_data):
        """
        Update and return an existing `Snippet` instance, given the validated data.
        """
        instance.title = validated_data.get('title', instance.title)
        instance.code = validated_data.get('code', instance.code)
        instance.linenos = validated_data.get('linenos', instance.linenos)
        instance.language = validated_data.get('language', instance.language)
        instance.style = validated_data.get('style', instance.style)
        instance.save()
        return instance

settings.py

"""
Django settings for tutorial project.

Generated by 'django-admin startproject' using Django 3.1.1.

For more information on this file, see
[https://docs.djangoproject.com/en/3.1/topics/settings/](https://docs.djangoproject.com/en/3.1/topics/settings/)

For the full list of settings and their values, see
[https://docs.djangoproject.com/en/3.1/ref/settings/](https://docs.djangoproject.com/en/3.1/ref/settings/)
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'. {: id="build-paths-inside-the-project-like-this:-base-dir-/-'subdir'." }
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production {: id="quick-start-development-settings---unsuitable-for-production" }
# See [https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/](https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/) {: id="see-[https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/](https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/)" }

# SECURITY WARNING: keep the secret key used in production secret! {: id="security-warning:-keep-the-secret-key-used-in-production-secret!" }
SECRET_KEY = 'dd$4ovv6pc94&(s7_@qkgs-a7$)&+&%!2v_gjtl!3^(rp1h$ds'

# SECURITY WARNING: don't run with debug turned on in production! {: id="security-warning:-don't-run-with-debug-turned-on-in-production!" }
DEBUG = True

ALLOWED_HOSTS = []


# Application definition {: id="application-definition" }

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'snippets.apps.SnippetsConfig',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'tutorial.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'tutorial.wsgi.application'


# Database {: id="database" }
# [https://docs.djangoproject.com/en/3.1/ref/settings/#databases](https://docs.djangoproject.com/en/3.1/ref/settings/#databases) {: id="[https://docs.djangoproject.com/en/3.1/ref/settings/#databases](https://docs.djangoproject.com/en/3.1/ref/settings/#databases)" }

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation {: id="password-validation" }
# [https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators](https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators) {: id="[https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators](https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators)" }

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization {: id="internationalization" }
# [https://docs.djangoproject.com/en/3.1/topics/i18n/](https://docs.djangoproject.com/en/3.1/topics/i18n/) {: id="[https://docs.djangoproject.com/en/3.1/topics/i18n/](https://docs.djangoproject.com/en/3.1/topics/i18n/)" }

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images) {: id="static-files-(css,-javascript,-images)" }
# [https://docs.djangoproject.com/en/3.1/howto/static-files/](https://docs.djangoproject.com/en/3.1/howto/static-files/) {: id="[https://docs.djangoproject.com/en/3.1/howto/static-files/](https://docs.djangoproject.com/en/3.1/howto/static-files/)" }

STATIC_URL = '/static/'

manage.py

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

../migrations/0001_initial.py

# Generated by Django 3.1.1 on 2020-09-07 22:03 {: id="generated-by-django-3.1.1-on-2020-09-07-22:03" }

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Snippet',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('title', models.CharField(blank=True, default='', max_length=100)),
                ('code', models.TextField()),
                ('linenos', models.BooleanField(default=False)),
                ('language', models.CharField(choices=[('abap', 'ABAP'), ('abnf', 'ABNF'), ('ada', 'Ada'), ('adl', 'ADL'), ('agda', 'Agda'), ('aheui', 'Aheui'), ('ahk', 'autohotkey'), ('alloy', 'Alloy'), ('ampl', 'Ampl'), ('antlr', 'ANTLR'), ('antlr-as', 'ANTLR With ActionScript Target'), ('antlr-cpp', 'ANTLR With CPP Target'), ('antlr-csharp', 'ANTLR With C# Target'), ('antlr-java', 'ANTLR With Java Target'), ('antlr-objc', 'ANTLR With ObjectiveC Target'), ('antlr-perl', 'ANTLR With Perl Target'), ('antlr-python', 'ANTLR With Python Target'), ('antlr-ruby', 'ANTLR With Ruby Target'), ('apacheconf', 'ApacheConf'), ('apl', 'APL'), ('applescript', 'AppleScript'), ('arduino', 'Arduino'), ('as', 'ActionScript'), ('as3', 'ActionScript 3'), ('aspectj', 'AspectJ'), ('aspx-cs', 'aspx-cs'), ('aspx-vb', 'aspx-vb'), ('asy', 'Asymptote'), ('at', 'AmbientTalk'), ('augeas', 'Augeas'), ('autoit', 'AutoIt'), ('awk', 'Awk'), ('basemake', 'Base Makefile'), ('bash', 'Bash'), ('bat', 'Batchfile'), ('bbcbasic', 'BBC Basic'), ('bbcode', 'BBCode'), ('bc', 'BC'), ('befunge', 'Befunge'), ('bib', 'BibTeX'), ('blitzbasic', 'BlitzBasic'), ('blitzmax', 'BlitzMax'), ('bnf', 'BNF'), ('boa', 'Boa'), ('boo', 'Boo'), ('boogie', 'Boogie'), ('brainfuck', 'Brainfuck'), ('bst', 'BST'), ('bugs', 'BUGS'), ('c', 'C'), ('c-objdump', 'c-objdump'), ('ca65', 'ca65 assembler'), ('cadl', 'cADL'), ('camkes', 'CAmkES'), ('capdl', 'CapDL'), ('capnp', "Cap'n Proto"), ('cbmbas', 'CBM BASIC V2'), ('ceylon', 'Ceylon'), ('cfc', 'Coldfusion CFC'), ('cfengine3', 'CFEngine3'), ('cfm', 'Coldfusion HTML'), ('cfs', 'cfstatement'), ('chai', 'ChaiScript'), ('chapel', 'Chapel'), ('charmci', 'Charmci'), ('cheetah', 'Cheetah'), ('cirru', 'Cirru'), ('clay', 'Clay'), ('clean', 'Clean'), ('clojure', 'Clojure'), ('clojurescript', 'ClojureScript'), ('cmake', 'CMake'), ('cobol', 'COBOL'), ('cobolfree', 'COBOLFree'), ('coffee-script', 'CoffeeScript'), ('common-lisp', 'Common Lisp'), ('componentpascal', 'Component Pascal'), ('console', 'Bash Session'), ('control', 'Debian Control file'), ('coq', 'Coq'), ('cpp', 'C++'), ('cpp-objdump', 'cpp-objdump'), ('cpsa', 'CPSA'), ('cr', 'Crystal'), ('crmsh', 'Crmsh'), ('croc', 'Croc'), ('cryptol', 'Cryptol'), ('csharp', 'C#'), ('csound', 'Csound Orchestra'), ('csound-document', 'Csound Document'), ('csound-score', 'Csound Score'), ('css', 'CSS'), ('css+django', 'CSS+Django/Jinja'), ('css+erb', 'CSS+Ruby'), ('css+genshitext', 'CSS+Genshi Text'), ('css+lasso', 'CSS+Lasso'), ('css+mako', 'CSS+Mako'), ('css+mozpreproc', 'CSS+mozpreproc'), ('css+myghty', 'CSS+Myghty'), ('css+php', 'CSS+PHP'), ('css+smarty', 'CSS+Smarty'), ('cucumber', 'Gherkin'), ('cuda', 'CUDA'), ('cypher', 'Cypher'), ('cython', 'Cython'), ('d', 'D'), ('d-objdump', 'd-objdump'), ('dart', 'Dart'), ('dasm16', 'DASM16'), ('delphi', 'Delphi'), ('dg', 'dg'), ('diff', 'Diff'), ('django', 'Django/Jinja'), ('docker', 'Docker'), ('doscon', 'MSDOS Session'), ('dpatch', 'Darcs Patch'), ('dtd', 'DTD'), ('duel', 'Duel'), ('dylan', 'Dylan'), ('dylan-console', 'Dylan session'), ('dylan-lid', 'DylanLID'), ('earl-grey', 'Earl Grey'), ('easytrieve', 'Easytrieve'), ('ebnf', 'EBNF'), ('ec', 'eC'), ('ecl', 'ECL'), ('eiffel', 'Eiffel'), ('elixir', 'Elixir'), ('elm', 'Elm'), ('emacs', 'EmacsLisp'), ('email', 'E-mail'), ('erb', 'ERB'), ('erl', 'Erlang erl session'), ('erlang', 'Erlang'), ('evoque', 'Evoque'), ('extempore', 'xtlang'), ('ezhil', 'Ezhil'), ('factor', 'Factor'), ('fan', 'Fantom'), ('fancy', 'Fancy'), ('felix', 'Felix'), ('fennel', 'Fennel'), ('fish', 'Fish'), ('flatline', 'Flatline'), ('floscript', 'FloScript'), ('forth', 'Forth'), ('fortran', 'Fortran'), ('fortranfixed', 'FortranFixed'), ('foxpro', 'FoxPro'), ('freefem', 'Freefem'), ('fsharp', 'F#'), ('gap', 'GAP'), ('gas', 'GAS'), ('genshi', 'Genshi'), ('genshitext', 'Genshi Text'), ('glsl', 'GLSL'), ('gnuplot', 'Gnuplot'), ('go', 'Go'), ('golo', 'Golo'), ('gooddata-cl', 'GoodData-CL'), ('gosu', 'Gosu'), ('groff', 'Groff'), ('groovy', 'Groovy'), ('gst', 'Gosu Template'), ('haml', 'Haml'), ('handlebars', 'Handlebars'), ('haskell', 'Haskell'), ('haxeml', 'Hxml'), ('hexdump', 'Hexdump'), ('hlsl', 'HLSL'), ('hsail', 'HSAIL'), ('hspec', 'Hspec'), ('html', 'HTML'), ('html+cheetah', 'HTML+Cheetah'), ('html+django', 'HTML+Django/Jinja'), ('html+evoque', 'HTML+Evoque'), ('html+genshi', 'HTML+Genshi'), ('html+handlebars', 'HTML+Handlebars'), ('html+lasso', 'HTML+Lasso'), ('html+mako', 'HTML+Mako'), ('html+myghty', 'HTML+Myghty'), ('html+ng2', 'HTML + Angular2'), ('html+php', 'HTML+PHP'), ('html+smarty', 'HTML+Smarty'), ('html+twig', 'HTML+Twig'), ('html+velocity', 'HTML+Velocity'), ('http', 'HTTP'), ('hx', 'Haxe'), ('hybris', 'Hybris'), ('hylang', 'Hy'), ('i6t', 'Inform 6 template'), ('icon', 'Icon'), ('idl', 'IDL'), ('idris', 'Idris'), ('iex', 'Elixir iex session'), ('igor', 'Igor'), ('inform6', 'Inform 6'), ('inform7', 'Inform 7'), ('ini', 'INI'), ('io', 'Io'), ('ioke', 'Ioke'), ('irc', 'IRC logs'), ('isabelle', 'Isabelle'), ('j', 'J'), ('jags', 'JAGS'), ('jasmin', 'Jasmin'), ('java', 'Java'), ('javascript+mozpreproc', 'Javascript+mozpreproc'), ('jcl', 'JCL'), ('jlcon', 'Julia console'), ('js', 'JavaScript'), ('js+cheetah', 'JavaScript+Cheetah'), ('js+django', 'JavaScript+Django/Jinja'), ('js+erb', 'JavaScript+Ruby'), ('js+genshitext', 'JavaScript+Genshi Text'), ('js+lasso', 'JavaScript+Lasso'), ('js+mako', 'JavaScript+Mako'), ('js+myghty', 'JavaScript+Myghty'), ('js+php', 'JavaScript+PHP'), ('js+smarty', 'JavaScript+Smarty'), ('jsgf', 'JSGF'), ('json', 'JSON'), ('json-object', 'JSONBareObject'), ('jsonld', 'JSON-LD'), ('jsp', 'Java Server Page'), ('julia', 'Julia'), ('juttle', 'Juttle'), ('kal', 'Kal'), ('kconfig', 'Kconfig'), ('kmsg', 'Kernel log'), ('koka', 'Koka'), ('kotlin', 'Kotlin'), ('lagda', 'Literate Agda'), ('lasso', 'Lasso'), ('lcry', 'Literate Cryptol'), ('lean', 'Lean'), ('less', 'LessCss'), ('lhs', 'Literate Haskell'), ('lidr', 'Literate Idris'), ('lighty', 'Lighttpd configuration file'), ('limbo', 'Limbo'), ('liquid', 'liquid'), ('live-script', 'LiveScript'), ('llvm', 'LLVM'), ('llvm-mir', 'LLVM-MIR'), ('llvm-mir-body', 'LLVM-MIR Body'), ('logos', 'Logos'), ('logtalk', 'Logtalk'), ('lsl', 'LSL'), ('lua', 'Lua'), ('make', 'Makefile'), ('mako', 'Mako'), ('maql', 'MAQL'), ('mask', 'Mask'), ('mason', 'Mason'), ('mathematica', 'Mathematica'), ('matlab', 'Matlab'), ('matlabsession', 'Matlab session'), ('md', 'markdown'), ('mime', 'MIME'), ('minid', 'MiniD'), ('modelica', 'Modelica'), ('modula2', 'Modula-2'), ('monkey', 'Monkey'), ('monte', 'Monte'), ('moocode', 'MOOCode'), ('moon', 'MoonScript'), ('mosel', 'Mosel'), ('mozhashpreproc', 'mozhashpreproc'), ('mozpercentpreproc', 'mozpercentpreproc'), ('mql', 'MQL'), ('ms', 'MiniScript'), ('mscgen', 'Mscgen'), ('mupad', 'MuPAD'), ('mxml', 'MXML'), ('myghty', 'Myghty'), ('mysql', 'MySQL'), ('nasm', 'NASM'), ('ncl', 'NCL'), ('nemerle', 'Nemerle'), ('nesc', 'nesC'), ('newlisp', 'NewLisp'), ('newspeak', 'Newspeak'), ('ng2', 'Angular2'), ('nginx', 'Nginx configuration file'), ('nim', 'Nimrod'), ('nit', 'Nit'), ('nixos', 'Nix'), ('notmuch', 'Notmuch'), ('nsis', 'NSIS'), ('numpy', 'NumPy'), ('nusmv', 'NuSMV'), ('objdump', 'objdump'), ('objdump-nasm', 'objdump-nasm'), ('objective-c', 'Objective-C'), ('objective-c++', 'Objective-C++'), ('objective-j', 'Objective-J'), ('ocaml', 'OCaml'), ('octave', 'Octave'), ('odin', 'ODIN'), ('ooc', 'Ooc'), ('opa', 'Opa'), ('openedge', 'OpenEdge ABL'), ('pacmanconf', 'PacmanConf'), ('pan', 'Pan'), ('parasail', 'ParaSail'), ('pawn', 'Pawn'), ('peg', 'PEG'), ('perl', 'Perl'), ('perl6', 'Perl6'), ('php', 'PHP'), ('pig', 'Pig'), ('pike', 'Pike'), ('pkgconfig', 'PkgConfig'), ('plpgsql', 'PL/pgSQL'), ('pony', 'Pony'), ('postgresql', 'PostgreSQL SQL dialect'), ('postscript', 'PostScript'), ('pot', 'Gettext Catalog'), ('pov', 'POVRay'), ('powershell', 'PowerShell'), ('praat', 'Praat'), ('prolog', 'Prolog'), ('properties', 'Properties'), ('protobuf', 'Protocol Buffer'), ('ps1con', 'PowerShell Session'), ('psql', 'PostgreSQL console (psql)'), ('pug', 'Pug'), ('puppet', 'Puppet'), ('py2tb', 'Python 2.x Traceback'), ('pycon', 'Python console session'), ('pypylog', 'PyPy Log'), ('pytb', 'Python Traceback'), ('python', 'Python'), ('python2', 'Python 2.x'), ('qbasic', 'QBasic'), ('qml', 'QML'), ('qvto', 'QVTO'), ('racket', 'Racket'), ('ragel', 'Ragel'), ('ragel-c', 'Ragel in C Host'), ('ragel-cpp', 'Ragel in CPP Host'), ('ragel-d', 'Ragel in D Host'), ('ragel-em', 'Embedded Ragel'), ('ragel-java', 'Ragel in Java Host'), ('ragel-objc', 'Ragel in Objective C Host'), ('ragel-ruby', 'Ragel in Ruby Host'), ('raw', 'Raw token data'), ('rb', 'Ruby'), ('rbcon', 'Ruby irb session'), ('rconsole', 'RConsole'), ('rd', 'Rd'), ('reason', 'ReasonML'), ('rebol', 'REBOL'), ('red', 'Red'), ('redcode', 'Redcode'), ('registry', 'reg'), ('resource', 'ResourceBundle'), ('rexx', 'Rexx'), ('rhtml', 'RHTML'), ('ride', 'Ride'), ('rnc', 'Relax-NG Compact'), ('roboconf-graph', 'Roboconf Graph'), ('roboconf-instances', 'Roboconf Instances'), ('robotframework', 'RobotFramework'), ('rql', 'RQL'), ('rsl', 'RSL'), ('rst', 'reStructuredText'), ('rts', 'TrafficScript'), ('rust', 'Rust'), ('sarl', 'SARL'), ('sas', 'SAS'), ('sass', 'Sass'), ('sc', 'SuperCollider'), ('scala', 'Scala'), ('scaml', 'Scaml'), ('scdoc', 'scdoc'), ('scheme', 'Scheme'), ('scilab', 'Scilab'), ('scss', 'SCSS'), ('sgf', 'SmartGameFormat'), ('shen', 'Shen'), ('shexc', 'ShExC'), ('sieve', 'Sieve'), ('silver', 'Silver'), ('slash', 'Slash'), ('slim', 'Slim'), ('slurm', 'Slurm'), ('smali', 'Smali'), ('smalltalk', 'Smalltalk'), ('smarty', 'Smarty'), ('sml', 'Standard ML'), ('snobol', 'Snobol'), ('snowball', 'Snowball'), ('solidity', 'Solidity'), ('sourceslist', 'Debian Sourcelist'), ('sp', 'SourcePawn'), ('sparql', 'SPARQL'), ('spec', 'RPMSpec'), ('splus', 'S'), ('sql', 'SQL'), ('sqlite3', 'sqlite3con'), ('squidconf', 'SquidConf'), ('ssp', 'Scalate Server Page'), ('stan', 'Stan'), ('stata', 'Stata'), ('swift', 'Swift'), ('swig', 'SWIG'), ('systemverilog', 'systemverilog'), ('tads3', 'TADS 3'), ('tap', 'TAP'), ('tasm', 'TASM'), ('tcl', 'Tcl'), ('tcsh', 'Tcsh'), ('tcshcon', 'Tcsh Session'), ('tea', 'Tea'), ('termcap', 'Termcap'), ('terminfo', 'Terminfo'), ('terraform', 'Terraform'), ('tex', 'TeX'), ('text', 'Text only'), ('thrift', 'Thrift'), ('todotxt', 'Todotxt'), ('toml', 'TOML'), ('trac-wiki', 'MoinMoin/Trac Wiki markup'), ('treetop', 'Treetop'), ('ts', 'TypeScript'), ('tsql', 'Transact-SQL'), ('ttl', 'Tera Term macro'), ('turtle', 'Turtle'), ('twig', 'Twig'), ('typoscript', 'TypoScript'), ('typoscriptcssdata', 'TypoScriptCssData'), ('typoscripthtmldata', 'TypoScriptHtmlData'), ('ucode', 'ucode'), ('unicon', 'Unicon'), ('urbiscript', 'UrbiScript'), ('usd', 'USD'), ('vala', 'Vala'), ('vb.net', 'VB.net'), ('vbscript', 'VBScript'), ('vcl', 'VCL'), ('vclsnippets', 'VCLSnippets'), ('vctreestatus', 'VCTreeStatus'), ('velocity', 'Velocity'), ('verilog', 'verilog'), ('vgl', 'VGL'), ('vhdl', 'vhdl'), ('vim', 'VimL'), ('wdiff', 'WDiff'), ('webidl', 'Web IDL'), ('whiley', 'Whiley'), ('x10', 'X10'), ('xml', 'XML'), ('xml+cheetah', 'XML+Cheetah'), ('xml+django', 'XML+Django/Jinja'), ('xml+erb', 'XML+Ruby'), ('xml+evoque', 'XML+Evoque'), ('xml+lasso', 'XML+Lasso'), ('xml+mako', 'XML+Mako'), ('xml+myghty', 'XML+Myghty'), ('xml+php', 'XML+PHP'), ('xml+smarty', 'XML+Smarty'), ('xml+velocity', 'XML+Velocity'), ('xorg.conf', 'Xorg'), ('xquery', 'XQuery'), ('xslt', 'XSLT'), ('xtend', 'Xtend'), ('xul+mozpreproc', 'XUL+mozpreproc'), ('yaml', 'YAML'), ('yaml+jinja', 'YAML+Jinja'), ('zeek', 'Zeek'), ('zephir', 'Zephir'), ('zig', 'Zig')], default='python', max_length=100)), {: id="target'),-('antlr-java',-'antlr-with-java-target'),-('antlr-objc',-'antlr-with-objectivec-target'),-('antlr-perl',-'antlr-with-perl-target'),-('antlr-python',-'antlr-with-python-target'),-('antlr-ruby',-'antlr-with-ruby-target'),-('apacheconf',-'apacheconf'),-('apl',-'apl'),-('applescript',-'applescript'),-('arduino',-'arduino'),-('as',-'actionscript'),-('as3',-'actionscript-3'),-('aspectj',-'aspectj'),-('aspx-cs',-'aspx-cs'),-('aspx-vb',-'aspx-vb'),-('asy',-'asymptote'),-('at',-'ambienttalk'),-('augeas',-'augeas'),-('autoit',-'autoit'),-('awk',-'awk'),-('basemake',-'base-makefile'),-('bash',-'bash'),-('bat',-'batchfile'),-('bbcbasic',-'bbc-basic'),-('bbcode',-'bbcode'),-('bc',-'bc'),-('befunge',-'befunge'),-('bib',-'bibtex'),-('blitzbasic',-'blitzbasic'),-('blitzmax',-'blitzmax'),-('bnf',-'bnf'),-('boa',-'boa'),-('boo',-'boo'),-('boogie',-'boogie'),-('brainfuck',-'brainfuck'),-('bst',-'bst'),-('bugs',-'bugs'),-('c',-'c'),-('c-objdump',-'c-objdump'),-('ca65',-'ca65-assembler'),-('cadl',-'cadl'),-('camkes',-'camkes'),-('capdl',-'capdl'),-('capnp',-"cap'n-proto"),-('cbmbas',-'cbm-basic-v2'),-('ceylon',-'ceylon'),-('cfc',-'coldfusion-cfc'),-('cfengine3',-'cfengine3'),-('cfm',-'coldfusion-html'),-('cfs',-'cfstatement'),-('chai',-'chaiscript'),-('chapel',-'chapel'),-('charmci',-'charmci'),-('cheetah',-'cheetah'),-('cirru',-'cirru'),-('clay',-'clay'),-('clean',-'clean'),-('clojure',-'clojure'),-('clojurescript',-'clojurescript'),-('cmake',-'cmake'),-('cobol',-'cobol'),-('cobolfree',-'cobolfree'),-('coffee-script',-'coffeescript'),-('common-lisp',-'common-lisp'),-('componentpascal',-'component-pascal'),-('console',-'bash-session'),-('control',-'debian-control-file'),-('coq',-'coq'),-('cpp',-'c++'),-('cpp-objdump',-'cpp-objdump'),-('cpsa',-'cpsa'),-('cr',-'crystal'),-('crmsh',-'crmsh'),-('croc',-'croc'),-('cryptol',-'cryptol'),-('csharp',-'c#'),-('csound',-'csound-orchestra'),-('csound-document',-'csound-document'),-('csound-score',-'csound-score'),-('css',-'css'),-('css+django',-'css+django/jinja'),-('css+erb',-'css+ruby'),-('css+genshitext',-'css+genshi-text'),-('css+lasso',-'css+lasso'),-('css+mako',-'css+mako'),-('css+mozpreproc',-'css+mozpreproc'),-('css+myghty',-'css+myghty'),-('css+php',-'css+php'),-('css+smarty',-'css+smarty'),-('cucumber',-'gherkin'),-('cuda',-'cuda'),-('cypher',-'cypher'),-('cython',-'cython'),-('d',-'d'),-('d-objdump',-'d-objdump'),-('dart',-'dart'),-('dasm16',-'dasm16'),-('delphi',-'delphi'),-('dg',-'dg'),-('diff',-'diff'),-('django',-'django/jinja'),-('docker',-'docker'),-('doscon',-'msdos-session'),-('dpatch',-'darcs-patch'),-('dtd',-'dtd'),-('duel',-'duel'),-('dylan',-'dylan'),-('dylan-console',-'dylan-session'),-('dylan-lid',-'dylanlid'),-('earl-grey',-'earl-grey'),-('easytrieve',-'easytrieve'),-('ebnf',-'ebnf'),-('ec',-'ec'),-('ecl',-'ecl'),-('eiffel',-'eiffel'),-('elixir',-'elixir'),-('elm',-'elm'),-('emacs',-'emacslisp'),-('email',-'e-mail'),-('erb',-'erb'),-('erl',-'erlang-erl-session'),-('erlang',-'erlang'),-('evoque',-'evoque'),-('extempore',-'xtlang'),-('ezhil',-'ezhil'),-('factor',-'factor'),-('fan',-'fantom'),-('fancy',-'fancy'),-('felix',-'felix'),-('fennel',-'fennel'),-('fish',-'fish'),-('flatline',-'flatline'),-('floscript',-'floscript'),-('forth',-'forth'),-('fortran',-'fortran'),-('fortranfixed',-'fortranfixed'),-('foxpro',-'foxpro'),-('freefem',-'freefem'),-('fsharp',-'f#'),-('gap',-'gap'),-('gas',-'gas'),-('genshi',-'genshi'),-('genshitext',-'genshi-text'),-('glsl',-'glsl'),-('gnuplot',-'gnuplot'),-('go',-'go'),-('golo',-'golo'),-('gooddata-cl',-'gooddata-cl'),-('gosu',-'gosu'),-('groff',-'groff'),-('groovy',-'groovy'),-('gst',-'gosu-template'),-('haml',-'haml'),-('handlebars',-'handlebars'),-('haskell',-'haskell'),-('haxeml',-'hxml'),-('hexdump',-'hexdump'),-('hlsl',-'hlsl'),-('hsail',-'hsail'),-('hspec',-'hspec'),-('html',-'html'),-('html+cheetah',-'html+cheetah'),-('html+django',-'html+django/jinja'),-('html+evoque',-'html+evoque'),-('html+genshi',-'html+genshi'),-('html+handlebars',-'html+handlebars'),-('html+lasso',-'html+lasso'),-('html+mako',-'html+mako'),-('html+myghty',-'html+myghty'),-('html+ng2',-'html-+-angular2'),-('html+php',-'html+php'),-('html+smarty',-'html+smarty'),-('html+twig',-'html+twig'),-('html+velocity',-'html+velocity'),-('http',-'http'),-('hx',-'haxe'),-('hybris',-'hybris'),-('hylang',-'hy'),-('i6t',-'inform-6-template'),-('icon',-'icon'),-('idl',-'idl'),-('idris',-'idris'),-('iex',-'elixir-iex-session'),-('igor',-'igor'),-('inform6',-'inform-6'),-('inform7',-'inform-7'),-('ini',-'ini'),-('io',-'io'),-('ioke',-'ioke'),-('irc',-'irc-logs'),-('isabelle',-'isabelle'),-('j',-'j'),-('jags',-'jags'),-('jasmin',-'jasmin'),-('java',-'java'),-('javascript+mozpreproc',-'javascript+mozpreproc'),-('jcl',-'jcl'),-('jlcon',-'julia-console'),-('js',-'javascript'),-('js+cheetah',-'javascript+cheetah'),-('js+django',-'javascript+django/jinja'),-('js+erb',-'javascript+ruby'),-('js+genshitext',-'javascript+genshi-text'),-('js+lasso',-'javascript+lasso'),-('js+mako',-'javascript+mako'),-('js+myghty',-'javascript+myghty'),-('js+php',-'javascript+php'),-('js+smarty',-'javascript+smarty'),-('jsgf',-'jsgf'),-('json',-'json'),-('json-object',-'jsonbareobject'),-('jsonld',-'json-ld'),-('jsp',-'java-server-page'),-('julia',-'julia'),-('juttle',-'juttle'),-('kal',-'kal'),-('kconfig',-'kconfig'),-('kmsg',-'kernel-log'),-('koka',-'koka'),-('kotlin',-'kotlin'),-('lagda',-'literate-agda'),-('lasso',-'lasso'),-('lcry',-'literate-cryptol'),-('lean',-'lean'),-('less',-'lesscss'),-('lhs',-'literate-haskell'),-('lidr',-'literate-idris'),-('lighty',-'lighttpd-configuration-file'),-('limbo',-'limbo'),-('liquid',-'liquid'),-('live-script',-'livescript'),-('llvm',-'llvm'),-('llvm-mir',-'llvm-mir'),-('llvm-mir-body',-'llvm-mir-body'),-('logos',-'logos'),-('logtalk',-'logtalk'),-('lsl',-'lsl'),-('lua',-'lua'),-('make',-'makefile'),-('mako',-'mako'),-('maql',-'maql'),-('mask',-'mask'),-('mason',-'mason'),-('mathematica',-'mathematica'),-('matlab',-'matlab'),-('matlabsession',-'matlab-session'),-('md',-'markdown'),-('mime',-'mime'),-('minid',-'minid'),-('modelica',-'modelica'),-('modula2',-'modula-2'),-('monkey',-'monkey'),-('monte',-'monte'),-('moocode',-'moocode'),-('moon',-'moonscript'),-('mosel',-'mosel'),-('mozhashpreproc',-'mozhashpreproc'),-('mozpercentpreproc',-'mozpercentpreproc'),-('mql',-'mql'),-('ms',-'miniscript'),-('mscgen',-'mscgen'),-('mupad',-'mupad'),-('mxml',-'mxml'),-('myghty',-'myghty'),-('mysql',-'mysql'),-('nasm',-'nasm'),-('ncl',-'ncl'),-('nemerle',-'nemerle'),-('nesc',-'nesc'),-('newlisp',-'newlisp'),-('newspeak',-'newspeak'),-('ng2',-'angular2'),-('nginx',-'nginx-configuration-file'),-('nim',-'nimrod'),-('nit',-'nit'),-('nixos',-'nix'),-('notmuch',-'notmuch'),-('nsis',-'nsis'),-('numpy',-'numpy'),-('nusmv',-'nusmv'),-('objdump',-'objdump'),-('objdump-nasm',-'objdump-nasm'),-('objective-c',-'objective-c'),-('objective-c++',-'objective-c++'),-('objective-j',-'objective-j'),-('ocaml',-'ocaml'),-('octave',-'octave'),-('odin',-'odin'),-('ooc',-'ooc'),-('opa',-'opa'),-('openedge',-'openedge-abl'),-('pacmanconf',-'pacmanconf'),-('pan',-'pan'),-('parasail',-'parasail'),-('pawn',-'pawn'),-('peg',-'peg'),-('perl',-'perl'),-('perl6',-'perl6'),-('php',-'php'),-('pig',-'pig'),-('pike',-'pike'),-('pkgconfig',-'pkgconfig'),-('plpgsql',-'pl/pgsql'),-('pony',-'pony'),-('postgresql',-'postgresql-sql-dialect'),-('postscript',-'postscript'),-('pot',-'gettext-catalog'),-('pov',-'povray'),-('powershell',-'powershell'),-('praat',-'praat'),-('prolog',-'prolog'),-('properties',-'properties'),-('protobuf',-'protocol-buffer'),-('ps1con',-'powershell-session'),-('psql',-'postgresql-console-(psql)'),-('pug',-'pug'),-('puppet',-'puppet'),-('py2tb',-'python-2.x-traceback'),-('pycon',-'python-console-session'),-('pypylog',-'pypy-log'),-('pytb',-'python-traceback'),-('python',-'python'),-('python2',-'python-2.x'),-('qbasic',-'qbasic'),-('qml',-'qml'),-('qvto',-'qvto'),-('racket',-'racket'),-('ragel',-'ragel'),-('ragel-c',-'ragel-in-c-host'),-('ragel-cpp',-'ragel-in-cpp-host'),-('ragel-d',-'ragel-in-d-host'),-('ragel-em',-'embedded-ragel'),-('ragel-java',-'ragel-in-java-host'),-('ragel-objc',-'ragel-in-objective-c-host'),-('ragel-ruby',-'ragel-in-ruby-host'),-('raw',-'raw-token-data'),-('rb',-'ruby'),-('rbcon',-'ruby-irb-session'),-('rconsole',-'rconsole'),-('rd',-'rd'),-('reason',-'reasonml'),-('rebol',-'rebol'),-('red',-'red'),-('redcode',-'redcode'),-('registry',-'reg'),-('resource',-'resourcebundle'),-('rexx',-'rexx'),-('rhtml',-'rhtml'),-('ride',-'ride'),-('rnc',-'relax-ng-compact'),-('roboconf-graph',-'roboconf-graph'),-('roboconf-instances',-'roboconf-instances'),-('robotframework',-'robotframework'),-('rql',-'rql'),-('rsl',-'rsl'),-('rst',-'restructuredtext'),-('rts',-'trafficscript'),-('rust',-'rust'),-('sarl',-'sarl'),-('sas',-'sas'),-('sass',-'sass'),-('sc',-'supercollider'),-('scala',-'scala'),-('scaml',-'scaml'),-('scdoc',-'scdoc'),-('scheme',-'scheme'),-('scilab',-'scilab'),-('scss',-'scss'),-('sgf',-'smartgameformat'),-('shen',-'shen'),-('shexc',-'shexc'),-('sieve',-'sieve'),-('silver',-'silver'),-('slash',-'slash'),-('slim',-'slim'),-('slurm',-'slurm'),-('smali',-'smali'),-('smalltalk',-'smalltalk'),-('smarty',-'smarty'),-('sml',-'standard-ml'),-('snobol',-'snobol'),-('snowball',-'snowball'),-('solidity',-'solidity'),-('sourceslist',-'debian-sourcelist'),-('sp',-'sourcepawn'),-('sparql',-'sparql'),-('spec',-'rpmspec'),-('splus',-'s'),-('sql',-'sql'),-('sqlite3',-'sqlite3con'),-('squidconf',-'squidconf'),-('ssp',-'scalate-server-page'),-('stan',-'stan'),-('stata',-'stata'),-('swift',-'swift'),-('swig',-'swig'),-('systemverilog',-'systemverilog'),-('tads3',-'tads-3'),-('tap',-'tap'),-('tasm',-'tasm'),-('tcl',-'tcl'),-('tcsh',-'tcsh'),-('tcshcon',-'tcsh-session'),-('tea',-'tea'),-('termcap',-'termcap'),-('terminfo',-'terminfo'),-('terraform',-'terraform'),-('tex',-'tex'),-('text',-'text-only'),-('thrift',-'thrift'),-('todotxt',-'todotxt'),-('toml',-'toml'),-('trac-wiki',-'moinmoin/trac-wiki-markup'),-('treetop',-'treetop'),-('ts',-'typescript'),-('tsql',-'transact-sql'),-('ttl',-'tera-term-macro'),-('turtle',-'turtle'),-('twig',-'twig'),-('typoscript',-'typoscript'),-('typoscriptcssdata',-'typoscriptcssdata'),-('typoscripthtmldata',-'typoscripthtmldata'),-('ucode',-'ucode'),-('unicon',-'unicon'),-('urbiscript',-'urbiscript'),-('usd',-'usd'),-('vala',-'vala'),-('vb.net',-'vb.net'),-('vbscript',-'vbscript'),-('vcl',-'vcl'),-('vclsnippets',-'vclsnippets'),-('vctreestatus',-'vctreestatus'),-('velocity',-'velocity'),-('verilog',-'verilog'),-('vgl',-'vgl'),-('vhdl',-'vhdl'),-('vim',-'viml'),-('wdiff',-'wdiff'),-('webidl',-'web-idl'),-('whiley',-'whiley'),-('x10',-'x10'),-('xml',-'xml'),-('xml+cheetah',-'xml+cheetah'),-('xml+django',-'xml+django/jinja'),-('xml+erb',-'xml+ruby'),-('xml+evoque',-'xml+evoque'),-('xml+lasso',-'xml+lasso'),-('xml+mako',-'xml+mako'),-('xml+myghty',-'xml+myghty'),-('xml+php',-'xml+php'),-('xml+smarty',-'xml+smarty'),-('xml+velocity',-'xml+velocity'),-('xorg.conf',-'xorg'),-('xquery',-'xquery'),-('xslt',-'xslt'),-('xtend',-'xtend'),-('xul+mozpreproc',-'xul+mozpreproc'),-('yaml',-'yaml'),-('yaml+jinja',-'yaml+jinja'),-('zeek',-'zeek'),-('zephir',-'zephir'),-('zig',-'zig')],-default='python',-max-length=100))," }
                ('style', models.CharField(choices=[('abap', 'abap'), ('algol', 'algol'), ('algol_nu', 'algol_nu'), ('arduino', 'arduino'), ('autumn', 'autumn'), ('borland', 'borland'), ('bw', 'bw'), ('colorful', 'colorful'), ('default', 'default'), ('emacs', 'emacs'), ('friendly', 'friendly'), ('fruity', 'fruity'), ('igor', 'igor'), ('inkpot', 'inkpot'), ('lovelace', 'lovelace'), ('manni', 'manni'), ('monokai', 'monokai'), ('murphy', 'murphy'), ('native', 'native'), ('paraiso-dark', 'paraiso-dark'), ('paraiso-light', 'paraiso-light'), ('pastie', 'pastie'), ('perldoc', 'perldoc'), ('rainbow_dash', 'rainbow_dash'), ('rrt', 'rrt'), ('sas', 'sas'), ('solarized-dark', 'solarized-dark'), ('solarized-light', 'solarized-light'), ('stata', 'stata'), ('stata-dark', 'stata-dark'), ('stata-light', 'stata-light'), ('tango', 'tango'), ('trac', 'trac'), ('vim', 'vim'), ('vs', 'vs'), ('xcode', 'xcode')], default='friendly', max_length=100)),
            ],
            options={
                'ordering': ['created'],
            },
        ),
    ]

URL = Uniform Resource Locator
- a Django URL configuration matches a unique URL with a project resource
by matching a Python path using dot notation:
package.module.class.method package.module.function.attribute

** Django's urls package provides dozens of functions and classes for working with different URL formats, name resolution, exception handling, and other navigational utilities, but at its MOST basic:

it allows you to map a URL to a function or class within your
Django project:

   - App1 <= path('app1', app1.views.some_view())

   - App2

MVC?

Django = MVT = “model, view, template”
https://djangobook.com/mdj2-django-structure/

view
- describes the data that gets presented to the user aka which data you see.
- is the python callback function for a particular URL in the view, because that callback describes which data is presented.

-> delegates to a…

template - describes how you see it.

“controller” - the framework itself: the machinery that sends a request to the appropriate view, according to the Django URL configuration.

DJANGO TEMPLATE [client side]


             [server side]

        |                      |

App Logic               VIEW Logic

        |                      |

            MODEL(s)

                    |           [django framework]

                    |

             database

Why PostgreSQL?
- reccomended by Django book
- python can be used as a procedural language
- JSON support w/out NoSQL
- Data type changes of a column w/out rewriting the table
- geographical data w/ GeoDjangos

###################
# modeling custom fields {: id="#-modeling-custom-fields" }
###################
from django.db.models import CharField {: id="from-django.db.models-import-charfield" }

DAY_OF_THE_WEEK = {
    1 : 'Sunday',
    2 : 'Monday',
    3 : 'Tuesday',
    4 : 'Wednesday',
    5 : 'Thursday',
    6 : 'Friday',
    7 : 'Saturday'
}

class DayOfTheWeekField(models.CharField):
    def __init__(self, *args, **kwargs):
        kwargs['choices']=tuple(sorted(DAY_OF_THE_WEEK.items()))
        kwargs['max_length']=1
        super(DayOfTheWeekField, self).__init__(*args, **kwargs)





#####################
# example resolution order {: id="#-example-resolution-order" }
######################
 {: id="" }
class Destination(models.Model):
    city_name=models.CharField()

class Trip(models.Model):
    departing_on=models.DateField()
    returning_on=models.DateField()
    destinations=models.ManyToManyField(Destination)

class Activity(models.Model):
    destination=models.ForeignKey(Destination, null=False)
    trip=models.ForeignKey(Trip, null=False)



class Destination(models.Model):
    city_name=models.CharField(max_length=50)

class Trip(models.Model):
    departing_on=models.DateField()
    returning_on=models.DateField()
    destinations=models.ManyToManyField(Destination, through='Visit')

class Visit(models.Model):
    destination=models.ForeignKey(Destination)
    trip=models.ForeignKey(Trip)

class Activity(models.Model):
    name=models.CharField(max_length=50)
    visit=models.ForeignKey(Visit)


    # Trip 1 {: id="trip-1" }
    #     Destination 1 {: id="destination-1" }
    #     Destination 2 {: id="destination-2" }
    #       Activity 1 {: id="activity-1" }
    # Trip 2 {: id="trip-2" }
    #     Destination 1 {: id="destination-1" }
    #     Activity 2 {: id="activity-2" }


References:
- Advanced tutorial: How to write reusable apps