Sie sind auf Seite 1von 2

Template filters

default default_if_none yesno stringformat first last random length length_is join make_list value value "yes,no,none" "s" escape force_escape safe dont escape escapejs \x20 escapes iriencode IRI to URI urlencode %20 escapes add divisibleby floatformat filesizeformat get_digit pluralize date time timesince timeuntil lower upper title capfirst slugify ljust rjust center wordwrap wordcount striptags removetags truncatewords truncatewords_html
adds closing tags

ue Iss 4

DJANGO CHEAT SHEET


Version 1.0
www.mercurytide.co.uk/careers
... - end tag required

GENERAL

ESCAPING

Template tags
{# 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 ifequal ifnotequal include load now regroup spaceless templatetag url widthratio
abc

python % formatting

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

5 3 decimal_places n "y,ies" "date_format" "date_format" datetime datetime

NUMBERS

number ", " "1:5" "key" "key"

LISTS

nth-rightmost digit from integer

makes list of digits/characters

open or close block, brace, variable, comment

view arg,kwarg=value abc var1.attr as var2

slice dictsort dictsortreversed unordered_list


adds <li> tags

DATES & TIMES

with

Template date formats


h g H G i s a A 01 to 12 1 to 12 00 to 23 0 to 23 00 to 59 00 to 59 a.m. or p.m. AM or PM d j S 01 to 31 1 to 31 suffix: st, nd, rd or th Friday Fri 0 (Sun) to 6 (Sat) z W day of year: 0 to 365 week number: 1 to 53 F M b N m n y Y January Jan jan Jan., Feb., March, May 01 to 12 1 to 12 99 1999 T O Z f P r L t EST, MDT +0200 -43200 to 43200 (seconds) 1, 1:30 1 a.m., 1:30 p.m., noon
Thu, 21 Dec 2000 16:01:07 +0200

TIME

DAY

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

HOUR MIN & SEC AM & PM

MONTH

is leap year: True or False length of month: 28 to 31

width width width width

FORMATS

list_select_related inlines ordering prepopulated_fields radio_fields raw_id_fields save_as save_on_top search_fields

DAY OF WEEK MISC

TEXT FORMATTING

YEAR

MISC

InlineModelAdmin options
=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" ="Book" ="Books"

"a img" number number

linebreaks linebreaksbr urlize urlizetrunc cut

strips "x" from string

max_length "x"

linenumbers phone2numeric pprint

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"

Model fields
BooleanField NullBooleanField CharField max_length TextField SlugField max_length FilePathField path match recursive max_length IntegerField PositiveIntegerField AutoField DecimalField max_digits decimal_places DateTimeField auto_now auto_now_add TimeField auto_now auto_now_add =50 ="/home/images" =r"\.jpg$" =True =100 EmailField max_length IPAddressField URLField verify_exists max_length FileField upload_to max_length storage =10 =2 ImageField upload_to max_length storage height_field width_field XMLField schema_path =False =False =False =False =75

Relational model fields


ForeignKey(model) related_name limit_choices_to to_field ="model_set" =query_kwargs ="key_field"

ue Iss 4

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

=True =200 ="uploads/" =100 =FileSystemStorage ="uploads/" =100 =FileSystemStorage ="field_name" ="field_name" =path_to_RelaxNG_schema

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

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"

FloatField SmallIntegerField PositiveSmallIntegerField CommaSeparatedIntegerField max_length =50 DateField auto_now auto_now_add =False =False

Form fields
BooleanField NullBooleanField CharField max_length min_length IntegerField max_value min_value DecimalField max_value min_value max_digits decimal_places FloatField max_value min_value DateField input_formats DateTimeField input_formats TimeField input_formats ChoiceField choices MultipleChoiceField choices =list_of_formats =list_of_formats =list_of_formats =list_of_tuples =list_of_tuples ModelChoiceField queryset empty_label cache_choices ="----" =False IPAddressField FileField ImageField FilePathField path match recursive RegexField regex max_length min_length

Form fields common options


required label initial widget help_text error_messages =True ="Field name" ={} =Widget ="text" ={}

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

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

=False

Copyright 2008 Mercurytide Ltd.


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

Das könnte Ihnen auch gefallen