Model method order

Increasing standardisation and predictability of your code style helps other developers read your code.

The Django Coding Style suggests the following order of inner classes, methods and attributes:

  1. Field choice tuples
  2. Database fields
  3. Custom manager attributes
  4. class Meta
  5. def __str__()
  6. def save()
  7. def delete
  8. def get_absolute_url()
  9. Any custom methods

This standardisation is very useful when Python should be written to be read.

Are you affected by this? Audit your codebase in seconds to find out.

Configuring this check

Django Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code model-method-order in your pyproject.toml file.

Read more about configuring Django Doctor.