Sei sulla pagina 1di 2

Django Models Cheat Sheet

by Lewis Eason (lewiseason) via cheatography.com/6319/cs/1072/

Field Types Field Types (cont) Related Manager Methods

AutoField ManyTo​Man​yField model add x.ys_s​et.a​dd(y, ...)

BigInt​ege​rField limit_​cho​ices_to create x.ys_s​et.c​re​ate​(**​kwargs)

Binary​Field OneToO​neField remove* x.ys_s​et.r​em​ove(y1, y2, ...)

Boolea​nField clear* x.ys_s​et.c​lear()


Field Options
CharField max_length *Only available when
null FK(nul​l=True)
CommaS​epa​rat​edI​nte​ger​Fi max_length
eld blank
QuerySet API
DateField auto_now choices
auto_n​ow_add all X.ob​jec​ts.
db_column

DateTi​meField (as above) db_index filter filter​(**​kwargs)

Decima​lField max_digits db_tab​lespace exclude exclud​e(**​kw​args)

decima​l_p​laces default annotate annotate(


models.Co​unt​('c​ost') )
EmailField max_length editable
order_by [*fiel​ds_str]
FileField upload_to error_​mes​sages
reverse
storage help_text
distinct
FloatField primar​y_key
values *field​s_str
ImageField upload_to unique
values​_list *field​s_str
height​_field unique​_fo​r_[​dat​e|m​ont​h|year]
date(t​ime)?s dates(​field, kind, order)
width_​field verbos​e_name
none
Intege​rField validators
extra extra(​sel​ect={})
IPAddr​ess​Field
Field Lookups get (returns 1 obj) get( **kwargs )
Generi​cIP​Add​res​sField protocol
create (returns 1 create( **kwargs )
unpack​_ipv4 __exact
obj)
NullBo​ole​anField __iexact Case Insens​itive
get_or​_create get_or​_cr​eate( **kwargs
Positi​veI​nte​ger​Field __contains
(returns 1 obj) )
Positi​veS​mal​lIn​teg​erField __icon​tains
count
SlugField max_length __in Pass in a list
latest, earliest, first, last
SmallI​nte​ger​Field __gt, __gte, __lt, __lte Comparison
aggregate aggregate(
TextField __star​tswith, __ista​rts​with, __ends​with, models.Co​unt​('e​ntry') )
__iend​swith
TimeField auto_now delete
__range (inclu​sive) =(X, Y)
auto_n​ow_add
__year, __month, __day, __hour, __minute,
URLField max_length
__second
ForeignKey model
__week_day 1=Sun, 7=Sat
relate​d_name
__isnull
to_field
__regex
db_con​straint
(True)

on_delete

By Lewis Eason (lewiseason) Published 31st May, 2013. Sponsored by CrosswordCheats.com


cheatography.com/lewiseason/ Last updated 5th June, 2014. Learn to solve cryptic crosswords!
lewiseason.co.uk Page 1 of 2. http://crosswordcheats.com
Django Models Cheat Sheet
by Lewis Eason (lewiseason) via cheatography.com/6319/cs/1072/

Meta Options

abstract

app_label

db_table

db_tab​lespace

get_la​test_by

managed

order_​wit​h_r​esp​ect_to

ordering

permis​sions

proxy

unique​_to​gether

index_​tog​ether

verbos​e_name

verbos​e_n​ame​_plural

By Lewis Eason (lewiseason) Published 31st May, 2013. Sponsored by CrosswordCheats.com


cheatography.com/lewiseason/ Last updated 5th June, 2014. Learn to solve cryptic crosswords!
lewiseason.co.uk Page 2 of 2. http://crosswordcheats.com

Potrebbero piacerti anche