-
Notifications
You must be signed in to change notification settings - Fork 35
[DJ12] Order of Model's inner classes, methods, and fields does not follow the Django Style Guide
Rocio Aramberri edited this page May 24, 2020
·
4 revisions
The Django Style Guide specifies that the order of Model inner classes, attributes and methods should be as follows:
- All database fields
- Custom manager attributes
class Meta
def __str__()
def save()
def get_absolute_url()
- Any custom methods
from django.db import models
class Post(models.Model):
class Meta:
verbose_name = 'post'
title = models.CharField(max_length=150, null=True, blank=True)
def custom_method(self):
print("I should come after the save method")
def save(self):
super().save()
from django.db import models
class Post(models.Model):
title = models.CharField(max_length=150, null=True, blank=True)
class Meta:
verbose_name = 'post'
def save(self):
super().save()
def custom_method(self):
print("I should come after the save method")
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/#model-style