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:
3
+
        ordering = ('body',)
4
+
5
+
    body = models.TextField()

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
Update models.py

Instantly check if you have this issue for free

    Works with tools you use

    Read about how it works.