The Django coding style suggests a standard order of model attributes. 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.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
models.py
1
+
class CommentModel(models.Model):
2
+
    class Meta:
Suggested changes
+
    body = models.TextField()
+
-
 
-
    body = models.TextField()
Commit suggestion

The Django coding style suggests a standard order of model attributes. Increasing standardisation and predictability of your code style helps other developers read your code.

Read more
3
+
        ordering = ('body',)
4
+
5
+
    body = models.TextField()
Update models.py
We're your Django code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review 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 Code Review Doctor.