Skip to content
relekang edited this page Oct 1, 2014 · 7 revisions

Folder structure

See this subpage Folder structure

Imports

Divide imports into three sections: System libraries, third-party packages and stuff from lego:

Example

import os
import json

from django.conf import settings

from lego.utils import ice_cream

Use local imports within apps

# lego/events/views.py
from .models import Event

Do NOT use from models import Event.

Models

All models should inherit BasisModel

As mentioned in the Lincoln Loop django best practices

Make ‘em Fat

A common pattern in MVC-style programming is to build thick/fat models and thin controllers. For Django this translates to building models with lots of small methods attached to them and views which use those methods to keep their logic as minimal as possible. There are lots of benefits to this approach.

DRY: Rather than repeating the same logic in multiple views, it is defined once on the model. Testable: Breaking up logic into small methods on the model makes your code easier to unit test. Readable: By giving your methods friendly names, you can abstract ugly logic into something that is easily readable and understandable. For a good example of a fat model in Django, look at the definition of django.contrib.auth.models.User.