Cheat sheets can be really helpful when you’re trying a set of exercises related to a specific topic, or working on a project. Because you can only fit so much information on a single sheet of paper, most cheat sheets are a simple listing of syntax rules. This set of cheat sheets aims to remind you of syntax rules, but also remind you of important concepts as well. You can click here and download all of the original sheets in a single document.

Django 1.4 cheat sheet. Here is an updated version Jacob put together for PyCon 2012. DOWNLOAD Cheat Sheet for Django 1.4. Django 1.3 cheat sheet. Jacob put together this awesome cheat sheet that we handed out in the swag bag at PyCon 2011. Due to its popularity we have now posted it here online. DOWNLOAD Cheat Sheet (B&W version). Django cheat sheet made for perfectionists with deadlines. Start a project. Django-admin startproject projectname. Start the server.

A more recently updated version of these sheets (April 2021) is available through Leanpub. The updated version includes a sheet that focuses on Git basics, a printer-friendly b&w version of each sheet, and each sheet as a separate document. There is an option to download the fully updated set at no cost.

If you’d like to know when more resources become available, you can sign up for email notifications here.

  • Django - Cheat Sheet and free sample: Black Dashboard Sm0ke 11 Nov 2020. Hello, This article aims to help beginners to accommodate with Django, a top notch Python.
  • Home Instant Answers Django Model Cheat Sheet Next Steps. This is the home page for your Instant Answer and can be.

Overview Sheet

  • Beginner’s Python Cheat Sheet
    • Provides an overview of the basics of Python including variables, lists, dictionaries, functions, classes, and more.

Python Basics

  • Beginner’s Python Cheat Sheet - Lists
    • Focuses on lists: how to build and modify a list, access elements from a list, and loop through the values in a list. Also covers numerical lists, list comprehensions, tuples, and more.
  • Beginner’s Python Cheat Sheet - Dictionaries
    • Focuses on dictionaries: how to build and modify a dictionary, access the information in a dictionary, and loop through dictionaries in a variety of ways. Includes sections on nesting lists and dictionaries, using dictionary comprehensions, and more.
  • Beginner’s Python Cheat Sheet - If Statements and While Loops
    • Focuses on if statements and while loops: how to write conditional tests with strings and numerical data, how to write simple and complex if statements, and how to accept user input. Also covers a variety of approaches to using while loops.
  • Beginner’s Python Cheat Sheet - Functions
    • Focuses on functions: how to define a function and how to pass information to a function. Covers positional and keyword arguments, return values, passing lists, using modules, and more
  • Beginner’s Python Cheat Sheet - Classes
    • Focuses on classes: how to define and use a class. Covers attributes and methods, inheritance and importing, and more.
  • Beginner’s Python Cheat Sheet - Files and Exceptions
    • Focuses on working with files, and using exceptions to handle errors that might arise as your programs run. Covers reading and writing to files, try-except-else blocks, and storing data using the json module.
  • Beginner’s Python Cheat Sheet - Testing Your Code
    • Focuses on unit tests and test cases. How to test a function, and how to test a class.

Project-Focused Sheets

  • Beginner’s Python Cheat Sheet - Pygame
    • Focuses on creating games with Pygame. Creating a game window, rect objects, images, responding to keyboard and mouse input, groups, detecting collisions between game elements, and rendering text
  • Beginner’s Python Cheat Sheet - Matplotlib
    • Focuses on creating visualizations with Matplotlib. Making line graphs and scatter plots, customizing plots, making multiple plots, and working with time-based data.
  • Beginner’s Python Cheat Sheet - Plotly
    • Focuses on creating visualizations with Plotly. Making line graphs, scatter plots, and bar graphs, styling plots, making multiple plots, and working with geographical datasets.
  • Beginner’s Python Cheat Sheet - Django
    • Focuses on creating web apps with Django. Installing Django and starting a project, working with models, building a home page, using templates, using data, and making user accounts.

If you find any errors, please feel free to get in touch:


Twitter: @ehmatthes

Queryset can be constructed, filtered, sliced, and generally passed around without actually hitting the database. No database activity actually occurs until you do something to evaluate the queryset.

Querysets are evaluated when

  1. iterated
  2. slice
  3. pickle
  4. repr
  5. len
  6. list
  7. bool
  • Filter:Returns a new QuerySet containing objects that match the given lookup parameters.
  • Exclude: Returns a new QuerySet containing objects that do not match the given lookup parameters. In sql SELECT …WHERE NOT.
  • Annotate
  • order_by
  • reverse
  • distinct

  • values

  • value_list

  • dates and datetimes

  • all
  • union, intersection, difference

  • Select_related: Returns a QuerySet that will “follow” foreign-key relationships, selecting additional related-object data when it executes its query. This is a performance booster which results in a single more complex query but means later use of foreign-key relationships won’t require database queries

  • Prefetch related: similar to select_realted

    select_related works by creating an SQL join and including the fields of the related object in the SELECT statement. For this reason, select_related gets the related objects in the same database query. However, to avoid the much larger result set that would result from joining across a ‘many’ relationship, select_related is limited to single-valued relationships - foreign key and one-to-one.

    Oct 03, 2019 Helium is atomic number 2 on the periodic table, with the element symbol He. It is a colorless, flavorless gas, best known for its use in filling floating balloons. Here is a collection of facts about this lightweight, interesting element. He elemento. Helium (He), chemical element, inert gas of Group 18 (noble gases) of the periodic table. The second lightest element (only hydrogen is lighter), helium is a colourless, odourless, and tasteless gas that becomes liquid at −268.9 °C (−452 °F). The boiling and freezing points of helium are lower than those of any other known substance. Helium is the second most abundant element in the universe, but here on earth, it's rather rare. Most people guess that we extract helium from the air, but actually we dig it out of the ground. Helium can be found in certain parts of the world, notably in Texas, as a minor component in some sources of natural gas. Helium (from Greek: ἥλιος, romanized: helios, lit. 'sun') is a chemical element with the symbol He and atomic number 2. It is a colorless, odorless, tasteless, non-toxic, inert, monatomic gas, the first in the noble gas group in the periodic table. Its boiling point is the lowest among all the elements.

    prefetch_related, on the other hand, does a separate lookup for each relationship, and does the ‘joining’ in Python. This allows it to prefetch many-to-many and many-to-one objects, which cannot be done using select_related, in addition to the foreign key and one-to-one relationships that are supported by select_related.

  • Extra: Sometimes, the Django query syntax by itself can’t easily express a complex WHERE clause. For these edge cases, Django provides the extra()QuerySet modifier — a hook for injecting specific clauses into the SQL generated by a QuerySet.

  • Defer: In some complex) expression except that the check to see if it refers to a valid field isn’t made until the outer queryset is resolved.

  • Latest

  • first and last
  • Aggregate:

  • Annotate

  • Follow relationships backwards ( how we use 'book' to specify the Publisher -> Book reverse foreign key hop))

  • Filter on annotation

  • Q objects (Logical operations)

  • F expressions: act as a reference to a model field within a query

  • Subquery() expressions

Learn COMPLEX queries by examples:

WINDOW: Window functions provide a way to apply functions on partitions. Unlike a normal aggregation function which computes a final result for each set defined by the group by, window functions operate on frames and partitions, and compute the result for each row.

**Exists:**is a Subquery subclass that uses an SQL EXISTS statement. In many cases it will perform better than a subquery since the database is able to stop evaluation of the subquery when a first matching row is found.

For example, to annotate each post with whether or not it has a comment from within the last day:

Django Cheat Sheet

Django Cheat Sheet 2020

Exists is a Subquery subclass that uses an SQL EXISTS statement. In many cases it will perform better than a subquery since the database is able to stop evaluation of the subquery when a first matching row is found.

Python Django Cheat Sheet

For example, to annotate each post with whether or not it has a comment from within the last day:

Django Cheat Sheet 2021

more examples

If you want to write django queries try answering these questions in django ORM


Django documentaion