Skip to content

Commit

Permalink
extra docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KommuSoft committed Sep 17, 2023
1 parent dc32c53 commit 5e9f642
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/source/api_fields.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
======
Fields
======

.. automodule:: django_enforced_choices.fields
:members:
6 changes: 6 additions & 0 deletions docs/source/api_fields_postgres.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
===============
Postgres fields
===============

.. automodule:: django_enforced_choices.fields.postgres
:members:
6 changes: 6 additions & 0 deletions docs/source/api_models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
======
Models
======

.. automodule:: django_enforced_choices.models
:members:
46 changes: 46 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Configuration file for the Sphinx documentation builder.

# -- Project information

project = "django-enforced-choices"
copyright = "2022, Willem Van Onsem"
author = "Willem Van Onsem"

release = "0.1"
version = "0.1.0"

from os import environ
from os.path import dirname
from sys import path

path.insert(0, dirname(dirname(dirname(__file__))))
environ.setdefault("DJANGO_SETTINGS_MODULE", "docs.source.settings")

import django

django.setup()

# -- General configuration

extensions = [
"sphinx.ext.duration",
"sphinx.ext.doctest",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
]

intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"sphinx": ("https://www.sphinx-doc.org/en/master/", None),
}
intersphinx_disabled_domains = ["std"]

templates_path = ["_templates"]

# -- Options for HTML output

# html_theme = 'sphinx_rtd_theme'

# -- Options for EPUB output
epub_show_urls = "footnote"
16 changes: 16 additions & 0 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
===============
Getting started
===============

Once the package is installed, you can use the `ChoicesConstraintModelMetaMixin` mixin in the models, for example:

.. code-block:: python3
from django.db import models
from django_enforced_choices import ChoicesConstraintModelMetaMixin
class Movie(ChoicesConstraintModelMetaMixin, models.Model):
genre = models.CharField(max_length=1, choices=[('d', 'drama'), ('h', 'horror')])
When we then run `makemigrations` it will create a model with the `genre` field, and include a `CheckConstraint` to restrict the values to `'d'` and `'h'`.
2 changes: 1 addition & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The package can be fetched as `django-enforced-choices`, so for example with `pi

.. code-block:: console
pip3 install django-enforced-choices`
pip3 install django-enforced-choices
The item is not a Django app, so one should not to include it in the `INSTALLED_APPS`. It is only a module that
offers some functionality to use in Django applications.
125 changes: 125 additions & 0 deletions docs/source/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""
Django settings for test_package project.
Generated by 'django-admin startproject' using Django 3.2.8.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "secret-key"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

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 = "testproject.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 = "testproject.wsgi.application"

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

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


# Password validation
# https://docs.djangoproject.com/en/3.2/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
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_ROOT = "/var"
STATIC_URL = "/static/"

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "django-enforced-choices"
version = "0.1"
authors = [{name = "Willem Van Onsem", email = "yourfriends@hapytex.eu"}]

[build-system]
requires = ['setuptools>=45', 'wheel', 'setuptools_scm[toml]>=6.2']
build-backend = 'setuptools.build_meta:__legacy__'

[tool.setuptools_scm]
write_to = "_version.py"

[tool.black]
extend-exclude = '(.*/migrations/.*|setup)\.py'
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/hapytex/django-enforced-choices/
author = Willem Van Onsem
author_email = hapytexeu+gh@gmail.com
author_email = yourfriends@hapytex.eu
license = BSD-3-Clause
classifiers =
Environment :: Web Environment
Expand Down

0 comments on commit 5e9f642

Please sign in to comment.