Show Menu
Cheatography

Django 1.8 Best Practices Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

PEP8

- Use 4 spaces per indent­ation level.
- Separate top-level function and class defini­tions with two blank lines
- Method deô€…€nitions inside a class are separated by a single blank line.

Imports Order

1. Standard library imports.
2. Imports from core Django.
3. Imports from third-­party apps including those unrelated to Django.
4. Imports from the apps that you created as part of your Django project.
 

urls.py

Unders­cores
url(re­gex­='^­add/$', view=v­iew­s.a­dd_­top­ping, name='­add­_to­ppi­ng'),

*_tags.py

<app name>_­tags.py
 

NULL AND BLANK - How to use

Field Type
NULL
BLANK
CharField, TextField, SlugField, EmailF­ield, CommaS­epa­rat­edI­nteger- Field, UUIDField
Don't do this.
Okay.
FileField, ImageField
Don't do this.
Okay.
Boolea­nField
Don't do this.
Don't do this.
Intege­rField, FloatF­ield, Decima­lField, Durati­onF­ield, etc
Okay
Okay
DateTi­meF­ield, DateField, TimeField, etc.
Okay
Okay
Foreig­nKey, ManyTo­Man­yField, OneToO­neField
Okay
Okay
Generi­cIP­Add­res­sField
Okay
Okay
IPAddr­ess­Field
Not recomm­ended for use
Not recomm­ended for use