Django Models Cheat Sheet
by Lewis Eason (lewiseason) via cheatography.com/6319/cs/1072/
Field Types Field Types (cont) Related Manager Methods
AutoField ManyToManyField model add x.ys_set.add(y, ...)
BigIntegerField limit_choices_to create x.ys_set.create(**kwargs)
BinaryField OneToOneField remove* x.ys_set.remove(y1, y2, ...)
BooleanField clear* x.ys_set.clear()
Field Options
CharField max_length *Only available when
null FK(null=True)
CommaSeparatedIntegerFi max_length
eld blank
QuerySet API
DateField auto_now choices
auto_now_add all X.objects.
db_column
DateTimeField (as above) db_index filter filter(**kwargs)
DecimalField max_digits db_tablespace exclude exclude(**kwargs)
decimal_places default annotate annotate(
models.Count('cost') )
EmailField max_length editable
order_by [*fields_str]
FileField upload_to error_messages
reverse
storage help_text
distinct
FloatField primary_key
values *fields_str
ImageField upload_to unique
values_list *fields_str
height_field unique_for_[date|month|year]
date(time)?s dates(field, kind, order)
width_field verbose_name
none
IntegerField validators
extra extra(select={})
IPAddressField
Field Lookups get (returns 1 obj) get( **kwargs )
GenericIPAddressField protocol
create (returns 1 create( **kwargs )
unpack_ipv4 __exact
obj)
NullBooleanField __iexact Case Insensitive
get_or_create get_or_create( **kwargs
PositiveIntegerField __contains
(returns 1 obj) )
PositiveSmallIntegerField __icontains
count
SlugField max_length __in Pass in a list
latest, earliest, first, last
SmallIntegerField __gt, __gte, __lt, __lte Comparison
aggregate aggregate(
TextField __startswith, __istartswith, __endswith, models.Count('entry') )
__iendswith
TimeField auto_now delete
__range (inclusive) =(X, Y)
auto_now_add
__year, __month, __day, __hour, __minute,
URLField max_length
__second
ForeignKey model
__week_day 1=Sun, 7=Sat
related_name
__isnull
to_field
__regex
db_constraint
(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_tablespace
get_latest_by
managed
order_with_respect_to
ordering
permissions
proxy
unique_together
index_together
verbose_name
verbose_name_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