Professional Documents
Culture Documents
Django Cheat Sheet: Talented Developers Apply at WWW - Mercurytide.co - Uk/careers
Django Cheat Sheet: Talented Developers Apply at WWW - Mercurytide.co - Uk/careers
Booleans
[width_field=field_name] QuerySets
[max_length=number]
BooleanField Methods that return QuerySets QuerySet & Queries
FilePathField path=path
NullBooleanField [match=regex] all() exact=value|None lt=value
Numbers [recursive=False] none() iexact=value lte=value
IntegerField (>= 32 bit) [allow_files=True] filter(query) contains=string in=iterable|queryset
PositiveIntegerField (>= 32 bit) [allow_folders=False] exclude(query) icontains=string range=(start, end)
SmallIntegerField (DB specific size) [max_length=100] order_by(field, ...) startswith=string year=year
PositiveSmallIntegerField (DB specific size) Relationships reverse() istartswith=string month=1 – 12
BigIntegerField (64 bit) annotate(aggregate_query) endswith=string day=1 – 31
ForeignKey model (or "self")
DecimalField max_digits=number distinct([field, ...]) iendswith=string week_day=
[limit_choices_to=dict_or_Q]
decimal_places=number values(field, ...) regex=pattern 1 (Sun) – 7 (Sat)
[related_name=string]
FloatField values_list(field, ..., [flat=False]) iregex=pattern isnull=boolean
[to_field=field_name]
dates(field, kind="year|month|day", gt=value search=
[on_delete=action]
Strings [order="ASC|DESC"]) gte=value mysql fulltext query
OneToOneField model (or "self")
CharField max_length=number select_related([field, ...])
[limit_choices_to=dict_or_Q] Aggregation functions
TextField prefetch_related([field, ...])
[related_name=string] Count(field, [distinct=False])
SlugField [max_length=50] defer(field, ...)
ManyToManyField [to_field=field_name] Sum(field)
CommaSeparatedIntegerField max_length=number only(field, ...)
[on_delete=action] Max(field)
using(database_alias)
Strings [parent_link=False] Min(field)
select_for_update([nowait=False])
CharField max_length=number error_messages keys Avg(field)
extra([select=...], [select_params=...], [tables=...],
TextField StdDev(field, [sample=False])
null [where=...], [params=...], [order_by=...])
SlugField [max_length=50] Variance(field, [sample=False])
blank
CommaSeparatedIntegerField max_length=number unique
invalid Other methods
Dates & times get(query) → instance aggregate(aggregate_query) → dict
invalid_choice
DateField [auto_now=False] invalid_date create(query) → instance update(field=value, ...)
[auto_now_add=False] get_or_create(query) → (instance created) delete()
on_delete actions
DateTimeField [auto_now=False] earliest([field_name]) → instance in_bulk(ids) → instances dict, keyed by id
[auto_now_add=False] CASCADE SET_DEFAULT latest([field_name]) → instance bulk_create(instances, [batch_size=number])
TimeField [auto_now=False] PROTECT SET(value_or_function) exists() → boolean iterator() → iterator
[auto_now_add=False] SET_NULL DO_NOTHING count() → number
DJANGO CHEAT SHEET Version 1.5
ModelAdmin
List columns Form contents Change List
list_display = field_names filter_horizontal = field_names get_ordering(self, request) → field_names
list_display_links = field_names filter_vertical = field_names get_list_display(self, request) → field_names
list_editable = field_names radio_fields = dict: get_list_display_links(self, request, list_display) → field_names
list_filter = field_names {'choice_field': HORIZONTAL|VERTICAL, ...}
get_list_filter(self, request) → field_names
fieldsets = dict: Mercurytide is built upon a foundation of great
search_fields = field_names get_changelist(self, request, **kwargs) → ChangeList_class
( people. We love all things digital, and our clients
date_hierarchy = field_name get_changelist_form(self, request, **kwargs) → ModelForm_class
(title|None, { benefit from our full-service delivery - from
List actions get_changelist_formset(self, request, **kwargs) → ModelFormSet_class
['fields': field_names,] strategy and thorough production to ongoing
actions = list ['classes': list,] get_paginator(self, request, queryset, per_page, orphans=0,
support. In order to keep up with the demand for
actions_on_top = True ['description': string,] allow_empty_first_page=True) → paginator
}), ..
our expert services, Mercurytide is growing.
actions_on_bottom = False Add/Change Form
)
actions_selection_counter = True
save_on_top = False get_readonly_fields(self, request, obj=None) → field_names You will join a culture of exceptional people, who
ordering = field_names
Form layout get_prepopulated_fields(self, request, obj=None) → prepopulated_fields_dict pride themselves on being up to speed with the
List options get_fieldsets(self, request, obj=None) → fieldsets_tuple latest technologies. Our forward-thinking staff
add_form_template = template
ordering = field_names get_form(self, request, obj=None, **kwargs) → form_class have created bespoke solutions for a wide variety
change_form_template = template
list_select_related = False get_inline_instances(self, request, obj=None) → inline_instances_tuple of clients, from local retailers to global market
change_list_template = template
list_per_page = 100 get_formsets(self, request, obj=None) → yields InlineModelAdmins leaders. We champion the strengths of our staff
delete_confirmation_template = template
list_max_show_all = 200 formfield_for_choice_field(self, db_field, request, **kwargs) → field
delete_selected_confirmation_template = template and fuel progress by learning from each other.
paginator = paginator_class formfield_for_foreignkey(self, db_field, request, **kwargs) → field
object_history_template = template
Form contents formfield_for_manytomany(self, db_field, request, **kwargs) → field Life at Mercurytide is never dull; we have a busy
Templates
fields = field_names calendar of work, plus social events for our staff.
add_form_template = template
exclude = field_names
change_form_template = template
InlineModelAdmin If you are talented and think that your skill set
inlines = inline_classes can benefit our clients, then drop us a line today.
change_list_template = template Standard subclasses
readonly_fields = field_names
delete_confirmation_template = template StackedInline
raw_id_fields = field_names Don’t forget be our friend on Facebook and link
delete_selected_confirmation_template = template TabularInline
prepopulated_fields = dict
object_history_template = template up with us on LinkedIn.
{'slug': ('title',), ...}
Attributes & methods
form = form_class Queryset
formfield_overrides = dict model = model (mandatory) verbose_name = string
queryset(self, request) → queryset fk_name = field verbose_name_plural = string
save_as = False
form = ModelForm can_delete = True
Saving
formset = BaseInlineFormSet template = template
save_model(self, request, obj, form, is_change) – must call obj.save() extra = 1 get_formset(self, request, obj=None) →
delete_model(self, request, obj) – must call obj.delete() max_num = number BaseInlineFormSet_class
save_formset(self, request, form, formset, is_change) – must call formset.save()
save_related(self, request, form, formsets, is_change) - must call save() for each formset
AdminSite
Permissions
login_form = form
has_add_permission(self, request) → boolean
has_change_permission(self, request, obj=None) → boolean
index_template = template Talented developers apply at
login_template = template
has_delete_permission(self, request, obj=None) → boolean
logout_template = template
www.mercurytide.co.uk/careers
URLs password_change_template = template
get_urls(self) → urlpatterns password_change_done_template = template