You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[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
Don't
fromdjango.dbimportmodelsclassPost(models.Model):
classMeta:
verbose_name='post'title=models.CharField(max_length=150, null=True, blank=True)
defcustom_method(self):
print("I should come after the save method")
defsave(self):
super().save()
Do
fromdjango.dbimportmodelsclassPost(models.Model):
title=models.CharField(max_length=150, null=True, blank=True)
classMeta:
verbose_name='post'defsave(self):
super().save()
defcustom_method(self):
print("I should come after the save method")