|
1 | 1 | # Django Extra Checks |
2 | 2 |
|
3 | | -Useful checks for Django Checks Frameworks |
| 3 | +Collection of useful checks for Django Checks Frameworks |
| 4 | + |
| 5 | +## Checks |
| 6 | + |
| 7 | +### Models |
| 8 | + |
| 9 | +- **extra-checks-config** - settings.EXTRA_CHECKS is valid config for django-extra-checks (always enabled). |
| 10 | +- **model-attribute** - Each Model in the project must have all attributes from `attrs` setting specified. |
| 11 | +- **model-meta-attribute** - Each Model.Meta in the project must have all attributes from `attrs` setting specified. |
| 12 | +- **no-unique-together** - Use UniqueConstraint with the constraints option instead. |
| 13 | +- **no-index-together** - Use the indexes option instead. |
| 14 | +- **model-admin** - Each model must be registered in admin. |
| 15 | +- **field-file-upload-to** - FileField/ImageField must have non empty `upload_to` argument. |
| 16 | +- **field-verbose-name** - All model's fields must have verbose name. |
| 17 | +- **field-verbose-name-gettext** - verbose_name must use gettext. |
| 18 | +- **field-verbose-name-gettext-case** - Words in text wrapped with gettext must be in one case. |
| 19 | +- **field-help-text-gettext** - help_text must use gettext. |
| 20 | +- **field-text-null** - text fields shouldn't use `null=True`. |
| 21 | +- **field-boolean-null** - prefer using `BooleanField(null=True)` instead of `NullBooleanField`. |
| 22 | +- **field-null** - don't pass `null=False` to model fields (this is django default). |
| 23 | +- **field-foreign-key-db-index** - ForeignKey fields must specify `db_index` explicitly (to apply only to fields in indexes: `when: indexes`). |
| 24 | +- **field-default-null** - If field nullable (`null=True`), then |
| 25 | + `default=None` argument is redundant and should be removed. |
| 26 | + **WARNING** Be aware that setting is database dependent, |
| 27 | + eg. Oracle interprets empty strings as nulls as a result |
| 28 | + django uses empty string instead of null as default. |
| 29 | +- **field-choices-constraint** - Fields with choices must have companion CheckConstraint to enforce choices on database level, [details](https://adamj.eu/tech/2020/01/22/djangos-field-choices-dont-constrain-your-data/). |
| 30 | + |
| 31 | +### DRF Serializers |
| 32 | + |
| 33 | +- **drf-model-serializer-extra-kwargs** - ModelSerializer's extra_kwargs must not include fields that specified on serializer. |
| 34 | +- **drf-model-serializer-meta-attribute** - Each ModelSerializer.Meta must have all attributes specified in `attrs`, [use case](https://hakibenita.com/django-rest-framework-slow#bonus-forcing-good-habits). |
4 | 35 |
|
5 | 36 | ## Settings |
6 | 37 |
|
@@ -80,37 +111,6 @@ EXTRA_CHECKS = { |
80 | 111 | } |
81 | 112 | ``` |
82 | 113 |
|
83 | | -## Checks |
84 | | - |
85 | | -### Models |
86 | | - |
87 | | -- **extra-checks-config** - settings.EXTRA_CHECKS is valid config for django-extra-checks (always enabled). |
88 | | -- **model-attribute** - Each Model in the project must have all attributes from `attrs` setting specified. |
89 | | -- **model-meta-attribute** - Each Model.Meta in the project must have all attributes from `attrs` setting specified. |
90 | | -- **no-unique-together** - Use UniqueConstraint with the constraints option instead. |
91 | | -- **no-index-together** - Use the indexes option instead. |
92 | | -- **model-admin** - Each model must be registered in admin. |
93 | | -- **field-file-upload-to** - FileField/ImageField must have non empty `upload_to` argument. |
94 | | -- **field-verbose-name** - All model's fields must have verbose name. |
95 | | -- **field-verbose-name-gettext** - verbose_name must use gettext. |
96 | | -- **field-verbose-name-gettext-case** - Words in text wrapped with gettext must be in one case. |
97 | | -- **field-help-text-gettext** - help_text must use gettext. |
98 | | -- **field-text-null** - text fields shouldn't use `null=True`. |
99 | | -- **field-boolean-null** - prefer using `BooleanField(null=True)` instead of `NullBooleanField`. |
100 | | -- **field-null** - don't pass `null=False` to model fields (this is django default). |
101 | | -- **field-foreign-key-db-index** - ForeignKey fields must specify `db_index` explicitly (to apply only to fields in indexes: `when: indexes`). |
102 | | -- **field-default-null** - If field nullable (`null=True`), then |
103 | | - `default=None` argument is redundant and should be removed. |
104 | | - **WARNING** Be aware that setting is database dependent, |
105 | | - eg. Oracle interprets empty strings as nulls as a result |
106 | | - django uses empty string instead of null as default. |
107 | | -- **field-choices-constraint** - Fields with choices must have companion CheckConstraint to enforce choices on database level, [details](https://adamj.eu/tech/2020/01/22/djangos-field-choices-dont-constrain-your-data/). |
108 | | - |
109 | | -### DRF Serializers |
110 | | - |
111 | | -- **drf-model-serializer-extra-kwargs** - ModelSerializer's extra_kwargs must not include fields that specified on serializer. |
112 | | -- **drf-model-serializer-meta-attribute** - Each ModelSerializer.Meta must have all attributes specified in `attrs`, [use case](https://hakibenita.com/django-rest-framework-slow#bonus-forcing-good-habits). |
113 | | - |
114 | 114 | ## Development |
115 | 115 |
|
116 | 116 | Install dev deps in virtualenv `pip install -e .[dev]`. |
|
0 commit comments