Django 1.3 Cheatsheet
Django 1.3 Cheatsheet
Chainable
unique_for_date
= “date_field” DecimalField fields
= ["field_name", …]
none()
unique_for_month
= “month_field” max_digits = 10 fieldsets
only(*fields)
verbose_name
= “Field Name” decimal_places =2
= [("Name", {"fields": ["field_name", …]}), …]
order_by(*fields)
validators
= [validator_obj, …] EmailField filter_horizontal
= ["m2m_field", …]
raw(sql, params)
max_length = 75 reverse() filter_vertical
= ["m2m_field", …]
Model Meta options form = ModelFormClass
FileField select_related(‘field’, ‘field2’, …, depth=1)
using(“db_alias”) formfield_overrides
abstract = False
upload_to
= “files/%Y/%m/%d”
values(*fields)
= {TextField: {"widget": MyWidget}, …}
app_label = "applabel" storage = file_storage_obj
values_list(*fields) inlines
= [InlineClass, …]
db_table = "table_name" max_length = 100
values_list(field, flat=True) list_display
= ["field_name", callable, …]
db_tablespace = "space_name" FilePathField list_display_links
= ['field_name', …]
get_latest_by = "field_name"
path
= “/var/images” list_editable
= ['field_name', …]
managed = False
match
= r”\.pdf$” get(**lookups) list_filter
= ['field_name', …]
order_with_respect_to = "field" recursive = True create(**attributes) list_per_page = 100
ordering
= ["field_name", …] max_length = 100 get_or_create(**attributes, defaults={}) list_select_related = False
Not chainable
permissions
= [("code", "text label"), …] count() object_history_template = 'admin/history.html',
FloatField
proxy = False in_bulk(id_list) ordering = ['field_name']
unique_together
= [("field1", "field2"), …] FileField iterator()
upload_to
= “/uploads” paginator = Paginator
verbose_name = "verbose name" latest(field) prepopulated_fields
= {'slug': ['title'], …}
verbose_name_plural = "plural verbose names" storage = file_storage_obj aggregate(**aggregations)
max_length = 100 radio_fields = {'fk_field': admin.HORIZONTAL, …}
exists() raw_id_fields
= ['fk_or_m2m_field', …]
Model relationships ImageField update(**attributes) readonly_fields
= ['field_name', …]
upload_to
= “/uploads” delete() save_as = False
ForeignKey(OtherModel) storage = file_storage_obj save_on_top = False
related_name
= “things”
height_field
= “field_name” Lookups
search_fields = ['field_name']
limit_choices_to
= Q(foo=”bar”, ...)
width_field
= “field_name”
to_field
= “key_field_name” max_length = 100 exact, iexact
= “string”
on_delete = (on_delete option) contains, icontains
= “string” add_view(self, request, form_url='', extra_context={})
IntegerField, PositiveIntegerField, PositiveSmallIntegerField startswith, endswith,
DJANGO 1.3 CHEATSHEET
error_messages = {"code": "Message", …} All widgets DJDT Debug better, faster. template strftime
CheckboxSelectMultiple B
required = True addslashes pluralize
validators
= [validator, …] ClearableFileInput c 2008-01-02T10:30:00.000123
capfirst pluralize:"es"
widget = WidgetClass DateInput %c Fri Mar 4 16:43:23 2011
center:"15" pluralize:"y,ies"
format = "%Y-%m-%d" cut:" " pprint d %d 01 - 31
Form fields date:"jS F Y H:i" random D %a Mon, Tue, …
DateTimeInput
format = "%Y-%m-%d %H:%M" default:"nothing" removetags:"span div" E (alternate long month)
BooleanField default_if_none:"nothing" rjust:"10"
FileInput f 1, 1:30
NullBooleanField dictsort:"key" safe F %B January, February, …
HiddenInput, MultipleHiddenInput dictsortreversed:"key" safeseq
CharField g %m 1 - 12
max_length = 100 MultiWidget divisibleby:"4" slice:"10:20"
G 0 - 23
min_length = 10 NullBooleanSelect escape slugify
escapejs stringformat:"s" h %I 01 - 12
ChoiceField PasswordInput H %H 00 - 23
filesizeformat striptags
choices
= [(1, "Choice 1"), …] render_value = False first time:"H:i" i %M 00 - 59 (minutes)
TypedChoiceField RadioSelect fix_ampersands timesince I
choices
= [(1, "Choice 1"), …] Select floatformat timesince:from_date j 1 - 31
coerce = callback(value) floatformat:"3" timeuntil
empty_value = "" SelectDateWidget %j 001 - 365
force_escape timeuntil:from_date
years
= [2010, 2011, …] l %A Monday, Tuesday, …
MultipleChoiceField get_digit:"2" truncatewords:"10"
SelectMultiple L (leap year?)
choices
= [(1, "Choice 1"), …] iriencode truncatewords_html:"10"
SplitDateTimeWidget join:"/" unordered_list m 01 - 12
TypedMultipleChoiceField
choices
= [(1, "Choice 1"), …] Textarea length upper M %b Jan, Feb, …
coerce = callback(value) TextInput length_is:"4" urlencode n 1 - 12
empty_value = "" linebreaks urlencode:"/+" N Jan., Feb., March, …
TimeInput linebreaksbr urlize
DateField format = "%H:%M:%S" O +0200
linenumbers urlizetrunc:"15"
input_formats
= ["%Y-%m-%d", …] P 1 a.m., noon, 2:30 p.m.
Model/Form field validators ljust:"10" wordcount
DateTimeField lower wordwrap:"20" r Thu, 21 Dec 2000 16:01:07 +0200
input_formats
= ["%Y-%m%d %H:%M", …] MaxLengthValidator(max_length) make_list yesno:"yeah,no,unknown" s %S 00 - 59 (seconds)
DecimalField MinLengthValidator(min_length) S st, nd, rd, th
Template tags
max_value = Decimal(100) MaxValueValidator(max_value) t 28 - 31
min_value = Decimal(10) MinValueValidator(min_value) T %Z EST, UTC, …
{% block name %}…{% endblock %}
max_digits = 10 RegexValidator(regex, message=None, code=None) u (microseconds)
{% csrf_token %}
DJANGO 1.3 CHEATSHEET
decimal_places =2 URLValidator(verify_exists=False) {% cycle "row1" "row2" [as varname] [silent] %} U (unix timestamp)
EmailField validate_email {% debug %} w %w 0 (Sun.) - 6 (Sat.)
validate_slug
FileField {% extends "base.html" %} W 1 - 53
validate_ipv4_address {% filter force_escape|lower %}…{% endfilter %}
FilePathField validate_comma_separated_integer_list %U 01 - 53
{% firstof var1 var2 "fallback" %}
path = "/home/images" y %y 99
{% for i in list [reversed] %}…{% empty %}…{% endfor %}
recursive = True Y %Y 1999
match = r"\.pdf"
Django Packages {{ forloop.counter }}
Find reusable apps and tools for your Django site. {{ forloop.counter0 }} x 03/04/11
FloatField http://djangopackages.com/ {{ forloop.revcounter }} X 16:43:23
max_value = 100.0 {{ forloop.revcounter0 }} z 0 - 365
min_value = 10.0 {{ forloop.first }}
Signals Z (tz offset, seconds)
ImageField {{ forloop.last }}
DATE_FORMAT (as defined in settings)
IntegerField django.db.models.signals {{ forloop.parentloop }}
{% if condition %}…{% else %}…{% endif %} DATETIME_FORMAT (as defined in settings)
max_value = 100 pre_init(sender, args, kwargs)
post_init(sender, args, kwargs) {% ifchanged %}…{% else %}…{% endifchanged %} SHORT_DATE_FORMAT (as defined in settings)
min_value = 10
pre_save(sender, instance, using) {% include "other/template.html" [with who="Jane" … [only]] %} SHORT_DATETIME_FORMAT (as defined in settings)
IPAddressField {% load [foo bar … from] other_library %}
post_save(sender, instance, created, using) HttpRequest HttpResponse
RegexField pre_delete(sender, instance, using) {% now "jS F Y H:i" %}
regex = r'\w+' post_delete(sender, instance, using) {% regroup people by gender as gender_list %}
__iter__() __init__(content=’’,
max_length = 100 m2m_changed(sender, instance, action, reverse, {% spaceless %}…{% endspaceless %}
build_absolute_uri(path) mimetype=None,
min_length = 10 model, pk_set, using) {% templatetag openblock / closeblock / openvariable /
COOKIES status=200,
SlugField class_prepared(sender) closevariable / openbrace / closebrace /
encoding content_type=None)
max_length = 100 post_syncdb(sender, app, created_models, opencomment / closecomment %}
FILES __delitem__(header)
min_length = 10 verbosity, interactive) {% url path.to.view arg1 arg2 arg3=v1 arg4=v2 [as the_url] %}
GET __getitem__(header)
{% widthratio this_value max_value 100 %}
TimeField django.core.signals get_full_path() __setitem__(header, val)
{% with alpha=1 beta=2 … %}…{% endwith %}
input_formats
= ["%H:%M:%S", …] request_started(sender) get_host() delete_cookie(key,
URLField request_finished(sender) is_ajax() path="/",
max_length = 100 got_request_exception(sender, request) Celery is_secure() domain=None)
min_length = 10 django.test.signals Distributed, asychronous task queue. META flush()
verify_exists = False template_rendered(sender, template, context) http://celeryproject.org/ method has_header(header)
validator_user_agent = "Django/1.3" path set_cookie(key, value,
django.db.backends.signals
django.shortcuts path_info max_age=None,
SplitDateTimeField connection_created(sender, connection)
POST expires=None,
input_date_formats
= ["%Y-%m-%d", …] django.contrib.auth.signals raw_post_data path="/",
render(request, template, context_dict={},
input_time+_formats
= ["%H:%M:%S", …] user_logged_in(sender, request, user) read(size=None) domain=None,
context_instance=RequestContext, content_type="text/html",
ModelChoiceField user_logged_out(sender, request, user) status=200, current_app=None) readline() secure=None,
queryset = Model.objects.all() django.contrib.comments.signals render_to_response(template, context_dict={}, readlines() httponly=False)
empty_label = u"------" comment_will_be_posted(sender, comment, request) context_instance=Contact, mimetype="text/html") REQUEST tell()
ModelMultipleChoiceField comment_was_posted(sender, comment, request) redirect(to, permanent=False, *args, **kw) session write(content)
queryset = Model.objects.all() comment_was_flagged(sender, comment, flag, get_object_or_404(Model, **lookup) urlconf
created, request) get_list_or_404(Model, **lookup) user