Sei sulla pagina 1di 2

Django Models Cheat Sheet

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

Field Types

Field Types (cont)

AutoField
BigIntegerField

ManyToManyField

BinaryField
BooleanField

Related Manager Methods


on_delete

add

x.ys_set.add(y, ...)

model

create

x.ys_set.create(**kwargs)

limit_choices_to

remove*

x.ys_set.remove(y1, y2, ...)

clear*

x.ys_set.clear()

OneToOneField

CharField

max_length

CommaSeparatedIntegerFi max_length
eld

*Only available when


Field Options

FK(null=True)

null

DateField

auto_now

blank

auto_now_add

choices

DateTimeField

(as above)

db_column

DecimalField

max_digits

QuerySet API
all

X.objects.

filter

filter(**kwargs)

db_index

exclude

exclude(**kwargs)

decimal_places

db_tablespace

annotate

annotate(

EmailField

max_length

default

FileField

upload_to

editable

storage

error_messages

FloatField

models.Count('cost') )
order_by
reverse
distinct

help_text

ImageField

upload_to

primary_key

height_field

unique

width_field

unique_for_[date|month|year]

IntegerField

verbose_name

IPAddressField

validators

GenericIPAddressField

protocol
unpack_ipv4

Field Lookups

NullBooleanField

__exact

PositiveIntegerField

__iexact

PositiveSmallIntegerField

__contains

SlugField

max_length

Case Insensitive

__icontains

TextField

__gt, __gte, __lt, __lte

Comparison

URLField

max_length

ForeignKey

model
related_name
to_field
db_constraint
(True)

values_list

*fields_str

date(time)?s

dates(field, kind, order)

none
extra

extra(select={})

get (returns 1 obj)

get( **kwargs )

create (returns 1

create( **kwargs )

get_or_create

get_or_create( **kwargs

(returns 1 obj)

latest, earliest, first, last


Pass in a list

auto_now_add

*fields_str

count

__in

auto_now

values

obj)

SmallIntegerField

TimeField

[*fields_str]

__startswith, __istartswith, __endswith,

aggregate

aggregate(
models.Count('entry') )

delete

__iendswith
__range

(inclusive) =(X, Y)

__year, __month, __day, __hour, __minute,


__second
__week_day

1=Sun, 7=Sat

__isnull
__regex

By Lewis Eason (lewiseason)

Published 31st May, 2013.

Sponsored by Readability-Score.com

cheatography.com/lewiseason/

Last updated 31st May, 2013.

Measure your website readability!

lewiseason.co.uk

Page 1 of 2.

https://readability-score.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 Readability-Score.com

cheatography.com/lewiseason/

Last updated 31st May, 2013.

Measure your website readability!

lewiseason.co.uk

Page 2 of 2.

https://readability-score.com

Potrebbero piacerti anche