You are on page 1of 2

ue

Iss

Template filters

www.mercurytide.co.uk/careers

python % formatting

Template tags

... - end tag required

url
widthratio

view arg,kwarg=value
abc

with

var1.attr as var2

first
last
random
length
length_is
join
make_list

number
", "

makes list of digits/characters

slice
dictsort
dictsortreversed
unordered_list

openblock

open or close block, brace, variable, comment

abc

"1:5"
"key"
"key"

adds <li> tags

Template date formats

ModelAdmin options
date_hierarchy
form
fieldsets
fields
filter_horizontal
filter_vertical
list_display
list_display_links
list_filter
list_per_page

="date_field"
=FormClass
=[("Details", {"fields": ("name",)})]
=list_of_field_names
=False
=False
=list_of_field_names
=list_of_field_names
=list_of_field_names
=100

1, 1:30
1 a.m., 1:30 p.m., noon
Thu, 21 Dec 2000 16:01:07 +0200

L
t

is leap year: True or False


length of month: 28 to 31

InlineModelAdmin options
list_select_related
inlines
ordering
prepopulated_fields
radio_fields
raw_id_fields
save_as
save_on_top
search_fields

=False
=list_of_InlineClasses
=list_of_field_names
={"slug": ("name",)}
={"agree": admin.VERTICAL}
=list_of_fk_fields
=False
=False
=list_of_field_names

model
fk_name
formset
extra
max_num
template
verbose_name
verbose_name_plural

=Book
="book"
=BaseInlineFormSet
=3
=0
="template"

5
3
decimal_places

pluralize

"y,ies"

date
time
timesince
timeuntil

"date_format"
"date_format"
datetime
datetime

lower
upper
title
capfirst
slugify
ljust
rjust
center
wordwrap
wordcount
striptags
removetags
truncatewords
truncatewords_html

width
width
width
width

nth-rightmost digit from integer

adds closing tags

linebreaks
linebreaksbr
urlize
urlizetrunc
cut

="Book"

strips "x" from string

="Books"

linenumbers
phone2numeric
pprint

"a img"
number
number

max_length
"x"

TEXT FORMATTING

99
1999

f
P
r

MISC

y
Y

EST, MDT
+0200
-43200 to 43200 (seconds)

FORMATS

day of year: 0 to 365


week number: 1 to 53

T
O
Z

TIME

z
W

YEAR

a.m. or p.m.
AM or PM

January
Jan
jan
Jan., Feb., March, May
01 to 12
1 to 12

MONTH

MIN
& SEC

a
A

Friday
Fri
0 (Sun) to 6 (Sat)

F
M
b
N
m
n

MISC

00 to 59
00 to 59

01 to 31
1 to 31
suffix: st, nd, rd or th

DAY OF
WEEK

HOUR

i
s

d
j
S

DAY

01 to 12
1 to 12
00 to 23
0 to 23

AM
& PM

h
g
H
G

add
divisibleby
floatformat
filesizeformat
get_digit

DATES
& TIMES

var1 var2
var1 var2
"template"
tag_library
"date format"
list_of_dicts by key as var

escape
force_escape
safe dont escape
escapejs \x20 escapes
iriencode IRI to URI
urlencode %20 escapes

NUMBERS

ifequal
ifnotequal
include
load
now
regroup
spaceless
templatetag

LISTS

{# one line comment #}


autoescape
on/off
block
name
comment
cycle
"one" "two" "three"
debug
extends
"template"
filter...
filter1|filter2
firstof
var1 var2 "default"
for...
item in a_list
ifelseendif
boolean expression
ifchanged
var

value
value
"yes,no,none"
"s"

ESCAPING

Version 1.0

default
default_if_none
yesno
stringformat

GENERAL

DJANGO CHEAT SHEET

ue
Iss
4

DJANGO CHEAT SHEET


Version 1.0

Model fields common options


null
blank
choices
db_column
db_index
db_tablespace
default
editable
help_text
primary_key
unique
unique_for_date
unique_for_month
unique_for_year

=False
=False
=list_of_tuples
="column_name"
=False
="tablespace_name"
=value_or_func
=True
="text"
=False
=False
="date_field"
="date_field"
="date_field"

Meta class options


abstract
db_table
db_tablespace
get_latest_by
order_with_respect_to
ordering
permissions
unique_together
verbose_name
verbose_name_plural

=False
="table_name"
="tablespace_name"
="field_name"
="fk_field_name"
=list_of_columns
=list_of_tuples
=list_of_tuples
="Model"
="Models"

Form fields common options


required
label
initial
widget
help_text
error_messages

=True
="Field name"
={}
=Widget
="text"
={}

Model fields

Relational model fields

BooleanField
NullBooleanField
CharField
max_length

DateTimeField
auto_now
auto_now_add

=False
=False

TimeField
auto_now
auto_now_add

=False
=False

TextField
SlugField
max_length

=50

FilePathField
path
match
recursive
max_length

EmailField
max_length

=75

="/home/images"
=r"\.jpg$"
=True
=100

IPAddressField
URLField
verify_exists
max_length

=True
=200

FileField
upload_to
max_length
storage

="uploads/"
=100
=FileSystemStorage

ImageField
upload_to
max_length
storage
height_field
width_field

="uploads/"
=100
=FileSystemStorage
="field_name"
="field_name"

XMLField
schema_path

=path_to_RelaxNG_schema

IntegerField
PositiveIntegerField
AutoField
DecimalField
max_digits
decimal_places

=10
=2

FloatField
SmallIntegerField
PositiveSmallIntegerField
CommaSeparatedIntegerField
max_length
=50
DateField
auto_now
auto_now_add

ForeignKey(model)
related_name
limit_choices_to
to_field

="model_set"
=query_kwargs
="key_field"

ManyToManyField(model)
="model_set"
related_name
=query_kwargs
limit_choices_to
="IntermediateModel"
through
=True
symmetrical
OneToOneField(model)
parent_link

="field"

GenericForeignKey("content_type_field",
"object_id_field")

Form error_messages keys


required
max_length
min_length
invalid
invalid_choice
max_value
min_value
max_digits

max_decimal_places
max_whole_digits
missing
empty
invalid_image
invalid_list
invalid_link

=False
=False

Form fields
ModelChoiceField
queryset
empty_label
cache_choices

BooleanField
NullBooleanField
CharField
max_length
min_length

FloatField
max_value
min_value
DateField
input_formats

=list_of_formats

IntegerField
max_value
min_value

DateTimeField
input_formats

=list_of_formats

DecimalField
max_value
min_value
max_digits
decimal_places

TimeField
input_formats

=list_of_formats

ChoiceField
choices

=list_of_tuples

MultipleChoiceField
choices

=list_of_tuples

="----"
=False

ModelMultipleChoiceField
queryset
=False
cache_choices
URLField
max_length
min_length
verify_exists
validator_user_agent
EmailField
max_length
min_length

=False

IPAddressField
FileField
ImageField
FilePathField
path
match
recursive

="/home/images"
=r"\.jpg$"
=False

RegexField
regex
max_length
min_length

Copyright 2008 Mercurytide Ltd.


Released under the Creative Commons
Attribution-Share Alike 2.5 UK: Scotland Licence.

You might also like