Skip to main content

Django Comb

Django Comb is a command-line tool aimed at untangling Django Models.

It provides a lint_models management command. This is a linter, allowing developers to define rules about their models.

Currently, the only rule is the no-inbound-foreign-keys rule, which prevents other models from defining ForeignKey, OneToOneField or ManyToManyField into a given model.

Usage

1. Install django_comb

Ensure django_comb is on the Python path and add it to INSTALLED_APPS:

# myproject/settings.py

INSTALLED_APPS = [
   "django_comb",
   ...
]

2. Define rules

  • Choose an installed Django app to place your rules. (It doesn't matter functionally, but usually you will want to use the app that contains the models you are protecting.)
  • Create a model_rules.toml in the directory in that app, alongside the app's models.py.
  • Add one or more rule definitions, in the form [rule.my-rule-id]. The second part of the TOML key (after the .) is your rule's unique id. See Supported Rules for examples.

3. Run the linter

Run the lint_models management command:

python manage.py lint_models

Supported rules

No inbound foreign keys

Prevents other models from defining a ForeignKey, OneToOneField or ManyToManyField into a set of models.

TOML Key Type Description
type String The rule type, must be "no_inbound_foreign_keys".
models String or Array of Strings The models to protect against inbound foreign keys pointing to them from other models, in the form app_label.ModelName. Supports Unix shell-style wildcards.
allowed String or Array of Strings (optional) Models that are allowed to point to models, in the form app_label.ModelName. Supports Unix shell-style wildcards.
silenced_violations String or Array of Strings (optional) Functionally identical to allowed, but indicates undesirable dependencies. Supports Unix shell-style wildcards.

Example

# path/to/some_app/model_rules.toml

[rule.no-fks-to-blue-or-green]
type = "no_inbound_foreign_keys"
models = "some_app.*"  # All models in some_app.
allowed = [
    # It's okay for these models to have a foreign key
    # to the models above.
    "some_app.*",
    "another_app.Orange",
]
# Models listed here also point to the models above, but they shouldn't.
# Including them here suppresses violations in the same way as
# `allowed`, but indicates that the violation is technical debt
# rather than intentional design.
silenced_violations = "another_app.Purple"

Exit codes

lint_models exits with the following status codes:

  • 0 if no violations were found.
  • 1 if violations were found.
  • 2 if it terminates abnormally, e.g. due to invalid configuration.

The get_model_rules command

To view the discovered model rules as JSON, run the get_model_rules management command:

$ python manage.py get_model_rules
[
  {
    "id": "all",
    "app_label": "another_app",
    "type": "no_inbound_foreign_keys",
    "models": [
      "some_app.*"
    ],
    "allowed": [
      "some_app.*",
      "another_app.Pur*"
    ],
    "silenced_violations": [
      "another_*.Orange"
    ],
    "extra_key_one": "foo",
    "extra_key_two": "bar"
  },
  {
    "id": "some-app-yellow",
    "app_label": "some_app",
    "type": "no_inbound_foreign_keys",
    "models": [
      "some_app.Yellow"
    ]
  }
]

This can be useful for building secondary tooling that tracks, say, the number of silenced_violations over time.

Metadata

Release files for django-comb 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-comb 1.0
File Size Uploaded Provenance Actions
django_comb-1.0.tar.gz 7.1 kB Without provenance Details for django_comb-1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-comb 1.0
File Interpreter ABI Platform Actions
django_comb-1.0-py3-none-any.whl Python 3 none any Details for django_comb-1.0-py3-none-any.whl

Total release size: 17.1 kB

Release files / django_comb-1.0.tar.gz

Download URL django_comb-1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4887d04b53c7eb0a54f7d1ed3c925065a7a350445d1558a9fdc6e3d874d04c9c
BLAKE2b-256 checksum
How to use checksums
e01ac5665d8f021fdff64aeae1a7a67aea003171dba9be41082901fea16a131d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / django_comb-1.0-py3-none-any.whl

Download URL django_comb-1.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6677bf819aafdff641f4f1efa1b53fc5cc7543f2acacf2e6f212d868d4e9f8f
BLAKE2b-256 checksum
How to use checksums
62d3c50891c06fda38e6119ab9c92da0611ac8cefed09fed31e5497d08b164e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for django-comb 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page