Coder Social home page Coder Social logo

djangoref's Introduction

Django Cheat Sheet

The goal of this in-progress repository will be to concisely capture / document common, core Django tools. Where appropriate, code samples will be added to highlight common use cases. Links to popular Stack Overflow answers will also be added to further explain topics.

Contents

Templates

  • Tags
  • Filters
  • Date formats
  • Field options (kwargs)
  • Fields
  • Meta attributes
    • abstract
    • app_label
    • db_table
    • get_latest_by
    • managed
    • ordering
    • permissions
    • proxy
    • unique_together
    • index_together
    • verbose_name
    • verbose_name_plural
  • Validators

Signals (NOTE: Perhaps nest these under their appropriate sections)

  • django.db.models.signals
  • django.core.signals
  • etc.

Querysets

  • Methods
    • all()
    • none()
    • filter(query)
    • exclude(query)
    • order_by(field...)
    • etc.
  • Queries (lookups)
    • exact
    • iexact
    • contains
    • gt
    • etc.
  • Aggregation functions

Forms

  • Common kwargs
    • required
    • label
    • help_text
    • initial
    • validators
    • widget
    • error_messages
    • localize
  • Fields
    • Boolean
    • Strings
    • Choices
    • Dates & Times
    • Numbers
    • Files
    • Internet
    • Misc
  • Validators
  • Views
    • Shortcuts
    • Decorators
    • GCBV
  • Formsets
  • Widgets
  • ModelForm & ModelFormSet

Admin

  • ModelAdmin
    • Options and callbacks
  • InlineModelAdmin
  • AdminSite

Settings

Testing

Urls

Management commands

  • Migrations
  • Shell
  • Server
  • etc.

Misc (not sure if these are staying)

Models

Model Field Options

Option Type Default
null boolean False
blank boolean False
choices iterable (list or tuple) None
db_column string None
db_index boolean False
db_tablespace string None
default value or callable NOT_PROVIDED
editable boolean True
error_messages dictionary None
help_text string '' (empty string)
primary_key boolean False
unique boolean False
unique_for_date string (DateField or DateTimeField name) None
unique_for_month string (DateField or DateTimeField name) None
unique_for_year string (DateField or DateTimeField name) None
verbose_name string None
validators list [] (empty list)

Model Fields

| Field Name | Options | Notes | |------------|------------------|----------|-|-| | AutoField | | You usually won’t need to use this directly. | | BigIntegerField | | For integers between -9223372036854775808 and 9223372036854775807 | | BinaryField | | Reminder: don't store files in the db | | BooleanField | | A true / false field. Use NullBooleanField to accept NULL values | | CharField | max_length=None | For small- to medium-sized strings | | CommaSeparatedIntegerField | max_length=None | | | DateField | [auto_now=False]
[auto_now_add=False] | | | DateTimeField | [auto_now=False]
[auto_now_add=False] | | | DecimalField | max_digits=None
decimal_places=None | Uses Python's Decimal type | | DurationField | | Modeled in Python by timedelta | | EmailField | [max_length=254] | Uses EmailValidator to validate input | | FileField | [upload_to=None]
[max_length=100] | | | FilePathField | path=None
[match=None]
[recursive=False]
[max_length=100] | | | FloatField | | Uses Python's float type | | ForeignKey | othermodel
[ondelete]
[related_name] | A many-to-one relationship. See additional arguments in the docs. | | GenericIPAddressField | [protocol='both']
[unpack_ipv4=False] | If blank=True, null must be True | | ImageField | [upload_to=None]
[height_field=None]
[width_field=None]
[max_length=100] | Requires the Pillow library | | IntegerField | | For integers between -2147483648 and 2147483647 | | ManyToManyField | othermodel
[related_name] | See additional arguments in the docs. | | NullBooleanField | | Like BooleanField, but allows NULL values by default | | OneToOneField | othermodel
[ondelete]
[parent_link=False]
[related_name] | | | PositiveIntegerField | | Like an IntegerField, but must be either positive or zero (0). | | PositiveSmallIntegerField | | A PositiveIntegerField for small values. Values from 0 to 32767 are safe in all databases. | | SlugField | [max_length=50]
[allow_unicode=False] | | | SmallIntegerField | | Integers between -32768 and 32767 are safe in all databases. | | TextField | | A large text field. max_length is not enforced at the db level. | | TimeField | [auto_now=False]
[auto_now_add=False] | Represented in Python by a datetime.time instance. | | URLField | [max_length=200] | A CharField for URLs | | UUIDField | | | |

djangoref's People

Contributors

rnevius avatar

Watchers

 avatar  avatar  avatar

Forkers

akwmak

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.