flake8-django-on-delete-comment

A flake8 extension to validate django models ForeignKey fields on on_delete CASCADE comment


Keywords
flake8, on_delete
License
MIT
Install
pip install flake8-django-on-delete-comment==0.0.3

Documentation

flake8-django-on-delete-comment

Build Status Maintainability Test Coverage

A flake8 extension to validate django models ForeignKey fields on on_delete CASCADE comment.

test_field = models.ForeignKey(  # allowed_cascade
    'TestModel',
    on_delete=models.CASCADE,
)

CASCADE can be not safe to choose, so such fields should be marked by comment.

Installation

pip install flake8-django-on-delete-comment

Example

Sample file:

# test.py

first_field = models.ForeignKey(  # allowed_cascade
    'FirstModel',
    on_delete=models.CASCADE,
)

second_field = models.ForeignKey(
    'SecondModel',
    on_delete=models.CASCADE,
)

third_field = models.ForeignKey(
    'ThirdModel',
    on_delete=models.PROTECT,
)

Usage:

$ flake8 test.py
test.py:6:1: CD001 field needs a valid comment for on_delete

Contributing

We would love you to contribute to our project. It's simple:

  1. Create an issue with bug you found or proposal you have. Wait for approve from maintainer.
  2. Create a pull request. Make sure all checks are green.
  3. Fix review comments if any.
  4. Be awesome.

Here are useful tips: