Model fields Common model field options ModelAdmin options & callbacks
Grove.io
AutoField null = False Enterprise chat, backed by IRC, built by Revsys. actions = ["method", callback, & ]
blank = False http://grove.io/ actions_on_bottom = False
BigIntegerField
choices = [(1, Choice 1 ), & ] actions_on_top = True
BooleanField, NullBooleanField QuerySet methods
QuerySet methods
db_column = column_name actions_selection_counter = True
CharField
db_index = False add_form_template = 'add_form.html'
all()
max_length = 100
db_tablespace = tablespace_name change_form_template = 'change_form.html'
annotate(**annotations)
CommaSeparatedIntegerField default = value_or_callable change_list_template = 'changelist.html',
dates(field, "year/month/day", "ASC/DESC")
max_length = 50 error_messages = { name : Message , & }, date_hierarchy = "date_field"
defer(*fields)
help_text = long help text delete_confirmation_template = 'delete.html'
DateField, DateTimeField distinct(*fields) (1.4)
primary_key = False delete_selected_confirmation_template = 'del.html'
exclude(**lookups)
DecimalField
unique = False exclude = ["field_name", & ]
filter(**lookups)
max_digits = 10
unique_for_date = date_field fields = ["field_name", & ]
none()
decimal_places = 2
unique_for_month = month_field fieldsets
only(*fields)
EmailField
verbose_name = Field Name = [("Name", {"fields": ["field_name", & ]}), & ]
order_by(*fields)
max_length = 75
validators = [validator_obj, & ] filter_horizontal = ["m2m_field", & ]
prefetch_related( field1 , field2 , & )
FileField filter_vertical = ["m2m_field", & ]
raw(sql, params)
Model Meta options
upload_to = files/%Y/%m/%d form = ModelFormClass
reverse()
abstract = False
storage = file_storage_obj formfield_overrides
select_for_update(nowait=False)
app_label = "applabel"
max_length = 100 = {TextField: {"widget": MyWidget}, & }
select_related( field , field2 , & , depth=1)
db_table = "table_name"
inlines = [InlineClass, & ]
FilePathField using( db_alias )
db_tablespace = "space_name"
list_display = ["fieldname", callable, & ]
path = /var/images values(*fields)
get_latest_by = "field_name"
list_display_links = ['field_name', & ]
match = r \.pdf$ values_list(*fields)
index_together = [("field1", "field2"), & ]
list_editable = ['field_name', & ]
recursive = True values_list(field, flat=True)
managed = False
list_filter = ['field_name', & ]
max_length = 100
order_with_respect_to = "field"
aggregate(**aggregations) list_max_show_all = 200
FloatField
ordering = ["field_name", & ]
bulk_create(list_of_objects) list_per_page = 100
FileField permissions = [("code", "text label"), & ]
count() list_select_related = False
upload_to = /uploads proxy = False
create(**attributes) object_history_template = 'admin/history.html',
storage = file_storage_obj unique_together = [("field1", "field2"), & ]
delete() ordering = ['field_name']
max_length = 100 verbose_name = "verbose name"
exists() paginator = Paginator
verbose_name_plural = "plural verbose names"
ImageField get(**lookups) prepopulated_fields = {'slug': ['title'], & }
upload_to = /uploads get_or_create(**attributes, defaults={}) radio_fields = {'fk_field': admin.HORIZONTAL, & }
ForeignKey on_delete options
storage = file_storage_obj in_bulk(id_list) raw_id_fields = ['fk_or_m2m_field', & ]
CASCADE cascades; default
height_field = field_name iterator() readonly_fields = ['field_name', & ]
PROTECT prevent related deletion
width_field = field_name latest(field) save_as = False
SET_NULL Set to NULL
max_length = 100 update(**attributes) save_on_top = False
SET_DEFAULT Set to field s default
search_fields = ['field_name']
IntegerField, PositiveIntegerField, PositiveSmallIntegerField
Lookups
SET(value) / SET(callback) Set to value / callback()
IPAddressField
add_view(self, request, form_url='', extra_context={})
DO_NOTHING No action (in Python)
exact, iexact = string
GenericIPAddressField changelist_view(self, request, extra_context={})
contains, icontains = string
Model/Form field validators
change_view(self, request, object_id, extra_context={})
protocol = both | IPv4 | IPv6 startswith, endswith,
delete_model(self, request, obj)
istartswith, iendswith = string
unpack_ipv4 = False MaxLengthValidator(max_length)
delete_view(self, request, object_id, extra_context={})
in = list / queryset
MinLengthValidator(min_length)
SlugField
formfield_for_choice_field(self, db_field, request, **kw)
gt, lt, gte, lte = date / int / float / decimal
MaxValueValidator(max_value)
max_length = 100
formfield_for_foreignkey(self, db_field, request, **kw)
range = (lower, upper)
MinValueValidator(min_value)
SmallIntegerField formfield_for_manytomany(self, db_field, request, **kw)
year, month, day = int
RegexValidator(regex, message=None, code=None)
get_list_display(self, request)
TextField isnull = bool
URLValidator(verify_exists=False)
get_list_display_link(self, request, list_display)
regex, iregex = r ^reg\. exp\.
TimeField validate_email
get_ordering(self, request)
validate_slug
URLField
Aggregation/annotation functions get_paginator(self, queryset, per_page, orphans=0,
validate_ipv4_address (also _ipv6_, _ipv46_)
Model relationships allow_empty_first_page=True)
Avg(field) StdDev(field, sample=False)
get_prepopulated_fields(self, request, obj=None)
Read the Docs
ForeignKey(OtherModel) Count(field, distinct=False) Sum(field)
get_readonly_fields(self, request, obj=None)
related_name = things Create, host, and browse documentation. Max(field) Variance(field, sample=false)
get_urls(self)
limit_choices_to = Q(foo= bar , ...) Min(field)
http://readthedocs.org/
has_add_permission(self, request)
to_field = key_field_name
has_change_permission(self, request, obj=None)
Signals
Signals
on_delete = (see right)
has_delete_permission(self, request, obj=None)
django.db.models.signals django.test.signals
ManyToManyField(OtherModel)
history_view(self, request, object_id, extra_context={})
pre_init, post_init(sender, args, kwargs)
related_name = things
settings_changed(sender, setting, value) message_user(self, request, message)
pre_save, post_save(sender, instance, using)
limit_choices_to = Q(foo= bar , ...)
template_rendered(sender, template, context) queryset(self, request)
pre_delete, post_delete(sender, instance, using)
to_field = key_field_name
save_formset(self, request, form, formset, change)
django.db.backends.signals
m2m_changed(sender, instance, action, reverse,
symmetrical = True,
save_model(self, request, obj, form, change)
connection_created(sender, connection)
model, pk_set, using)
through = RelationshipModel
save_related(self, request, obj=None)
django.contrib.auth.signals
class_prepared(sender)
db_table = table_name
user_logged_in, user_logged_out(sender, request, user)
post_syncdb(sender, app, created_models,
OneToOneField(OtherModel)
Modular search for Django.
user_login_failed(sender, credentials)
verbosity, interactive)
parent_link = False
Haystack
http://haystacksearch.org/
Find the needle you're looking for.
django.contrib.comments.signals
django.core.signals
related_name = thing
comment_will_be_posted(sender, comment, request)
request_started, request_finished(sender)
limit_choices_to = Q(foo= bar , ...)
Intelligent migrations.
comment_was_posted(sender, comment, request)
got_request_exception(sender, request)
to_field = key_field_name
comment_was_flagged(sender, comment, flag, created, request) http://south.aeracode.org/
on_delete = (see right)
Brought to you by
We know Django. http://revsys.com/
Chainable
Not chainable
DJANGO 1.5 CHEATSHEET
Datetime formatting
Datetime formatting
Datetime formatting
Common field options Django Debug Toolbar Tastypie
Debug better, faster. Creating delicious APIs for Django apps since 2010. template strftime
DJDT
error_messages = {"code": "Message", & }
http://django.me/djdt http://tastypieapi.org/
a a.m. / p.m.
help_text = "help text"
A %p AM / PM
initial = value Form widgets
Template filters
Template filters
b jan, feb, &
label = "field label"
add:"2" pluralize
All widgets B
localize = False
addslashes pluralize:"es"
attrs = {'class': 'fancy', & } c 2008-01-02T10:30:00.000123
required = True
capfirst pluralize:"y,ies"
%c Fri Mar 4 16:43:23 2011
validators = [validator, & ] CheckboxInput
center:"15" pprint
d %d 01 - 31
widget = WidgetClass check_test = callback(value)
cut:" " random
D %a Mon, Tue, &
Form fields CheckboxSelectMultiple
date:"jS F Y H:i" removetags:"span div"
e UTC, CST (timezone name)
ClearableFileInput
BooleanField, NullBooleanField default:"nothing" rjust:"10"
E (alternate long month)
default_if_none:"nothing" safe
DateInput f 1, 1:30
CharField
dictsort:"key" safeseq
format = "%Y-%m-%d" F %B January, February, &
max_length = 100
dictsortreversed:"key" slice:"10:20"
g %m 1 - 12
min_length = 10 DateTimeInput
divisibleby:"4" slugify
G 0 - 23
format = "%Y-%m-%d %H:%M"
ChoiceField, MultipleChoiceField
escape stringformat:"s"
h %I 01 - 12
choices = [(1, "Choice 1"), & ] FileInput
escapejs striptags
H %H 00 - 23
TypedChoiceField, TypedMultipleChoiceField HiddenInput, MultipleHiddenInput
filesizeformat time:"H:i"
i %M 00 - 59 (minutes)
choices = [(1, "Choice 1"), & ]
first timesince
MultiWidget j 1 - 31
coerce = callback(value)
fix_ampersands timesince:from_date
%j 001 - 365
NullBooleanSelect
empty_value = ""
floatformat timeuntil
l %A Monday, Tuesday, &
PasswordInput
ModelChoiceField, ModelMultipleChoiceField floatformat:"3" timeuntil:from_date
L (leap year?)
render_value = False
queryset = Model.objects.all() force_escape truncatecharsX: 9
m 01 - 12
RadioSelect
empty_label = u"------" get_digit:"2" truncatewords:"10"
M %b Jan, Feb, &
iriencode truncatewords_html:"10"
Select n 1 - 12
DateField
join:"/" unordered_list
N Jan., Feb., March, &
input_formats = ["%Y-%m-%d", & ] SelectDateWidget
length upper
o (ISO-8601 week-numbering year)
years = [2010, 2011, & ]
DateTimeField
length_is:"4" urlencode
O +0200
SelectMultiple
input_formats = ["%Y-%m%d %H:%M", & ]
linebreaks urlencode:"/+"
P 1 a.m., noon, 2:30 p.m.
SplitDateTimeWidget
DecimalField
linebreaksbr urlize
r Thu, 21 Dec 2000 16:01:07 +0200
max_value = Decimal(100) Textarea
linenumbers urlizetrunc:"15"
s %S 00 - 59 (seconds)
min_value = Decimal(10)
ljust:"10" wordcount
TextInput S st, nd, rd, th
max_digits = 10
lower wordwrap:"20"
t 28 - 31
TimeInput
decimal_places = 2
make_list yesno:"yeah,no,unknown"
T %Z EST, UTC, &
format = "%H:%M:%S"
EmailField phone2numeric
u (microseconds)
Celery
U (unix timestamp)
FileField, ImageField
Distributed, asychronous task queue. Template tags w %w 0 (Sun.) - 6 (Sat.)
FilePathField
http://celeryproject.org/ W 1 - 53
path = "/home/images"
{% block name %}& {% endblock %}
%U 01 - 53
recursive = True HttpRequest HttpResponse
{% csrf_token %}
y %y 99
match = r"\.pdf"
{% cycle "row1" "row2" [as varname] [silent] %}
__iter__() __init__(content= , Y %Y 1999
FloatField {% debug %}
body mimetype=None, x 03/04/11
max_value = 100.0 {% extends "base.html" %}
build_absolute_uri(path) status=200, X 16:43:23
min_value = 10.0 {% filter force_escape|lower %}& {% endfilter %}
COOKIES content_type=None) z 0 - 365
{% firstof var1 var2 "fallback" %}
IntegerField encoding __delitem__(header) Z (tz offset, seconds)
{% for i in list [reversed] %}& {% empty %}& {% endfor %}
max_value = 100 GET, POST, REQUEST __getitem__(header) DATE_FORMAT (as defined in settings)
{{ forloop.counter }}
min_value = 10 FILES __setitem__(header, val) DATETIME_FORMAT (as defined in settings)
DATETIME_FORMAT
{{ forloop.counter0 }}
SHORT_DATE_FORMAT
get_full_path() delete_cookie(key, SHORT_DATE_FORMAT (as defined in settings)
IPAddressField
{{ forloop.revcounter }}
SHORT_DATETIME_FORMAT
get_host() path="/", SHORT_DATETIME_FORMAT (as defined in settings)
GenericIPAddressField
{{ forloop.revcounter0 }}
get_signed_cookie(key) domain=None)
django.test.TestCase
protocol = both | IPv4 | IPv6 {{ forloop.first }}
is_ajax() flush()
{{ forloop.last }}
unpack_ipv4 = False is_secure() has_header(header)
client_class = django.test.client
{{ forloop.parentloop }}
META set_cookie, set_signed_cookie( fixtures = [ fix1.json , fix2.json , & ]
RegexField
{% if condition %}& {% elif condition %}& {% else %}& {% endif %}
method key, value,
urls = my.app.urls
regex = r'\w+'
{% ifchanged %}& {% else %}& {% endifchanged %}
path max_age=None,
multi_db = False
max_length = 100
{% include "other/template.html" [with who="Jane" & [only]] %}
path_info expires=None,
min_length = 10
assertContains, assertNotContains(resp, text, count=None,
{% load [foo bar & from] other_library %}
read(size=None) path="/",
SlugField
status_code=200, msg_prefix='', html=False)
{% now "jS F Y H:i" %}
readline(), readlines() domain=None,
max_length = 100
assertFieldOutput(cls, valid, invalid, field_args=None,
{% regroup people by gender as gender_list %}
session secure=None,
min_length = 10
field_kwargs=None, empty_value='')
{% spaceless %}& {% endspaceless %}
urlconf httponly=True)
assertFormError(resp, form, field, errors, msg_prefix='')
TimeField {% templatetag openblock / closeblock / openvariable /
user tell()
assertHTMLEqual, assertHTMLNotEqual(html1, html2, msg= )
input_formats = ["%H:%M:%S", & ] closevariable / openbrace / closebrace /
write(content)
assertXMLEqual, assertXMLNotEqual(xml1, xml2, msg= )
opencomment / closecomment %}
URLField
View shortcuts (django.shortcuts)
assertQuerysetEqual(qs, values, transform=repr, ordered=True)
{% url path.to.view arg1 arg2 arg3=v1 arg4=v2 [as the_url] %}
max_length = 100
assertRedirects(resp, url, status_code=302,
{% widthratio this_value max_value 100 %}
min_length = 10 render(request, template, context_dict={},
target_status_code=200, msg_prefix='')
{% verbatim %} & {% endverbatim %}
verify_exists = False context_instance=RequestContext, content_type="text/html",
assertTemplateUsed, assertTemplateNotUsed(resp, tmpl)
{% with alpha=1 beta=2 & %}& {% endwith %}
validator_user_agent = "Django/1.3" status=200, current_app=None)
redirect(to, permanent=False, *args, **kw)
with self.assertNumQueries(num, func): ...
SplitDateTimeField
Find more details in Django s official docs:
get_object_or_404(Model, **lookup)
with self.assertRaisesMessage(exe, msg): &
input_date_formats = ["%Y-%m-%d", & ]
get_list_or_404(Model, **lookup) Ą'
http://django.me/
with self.settings(SETTING= new_value ): ...
input_time+_formats = ["%H:%M:%S", & ]
Brought to you by
We know Django. http://revsys.com/
DJANGO 1.5 CHEATSHEET
Wyszukiwarka
Podobne podstrony:
Raine Cheats
cheats
Assassins Creed Cheats
cheatsheet SQL
Google Analytics Cheatsheet
cheatsheet?ministracja
CHEATS
Devil May Cry 4 Cheats
cheatsheet plsql
cheatsheet plsql
więcej podobnych podstron