db.models.query.QuerySet.aggregate()

aggregate(*args, **kwargs) Returns a dictionary of aggregate values (averages, sums, etc.) calculated over the QuerySet. Each argument to aggregate() specifies a value that will be included in the dictionary that is returned. The aggregation functions that are provided by Django are described in Aggregation Functions below. Since aggregates are also query expressions, you may combine aggregates with other aggregates or values to create complex aggregates. Aggregates specified using keyword a

db.models.query.QuerySet.first()

first() Returns the first object matched by the queryset, or None if there is no matching object. If the QuerySet has no ordering defined, then the queryset is automatically ordered by the primary key. Example: p = Article.objects.order_by('title', 'pub_date').first() Note that first() is a convenience method, the following code sample is equivalent to the above example: try: p = Article.objects.order_by('title', 'pub_date')[0] except IndexError: p = None

auth.models.UserManager.create_user()

create_user(username, email=None, password=None, **extra_fields) Creates, saves and returns a User. The username and password are set as given. The domain portion of email is automatically converted to lowercase, and the returned User object will have is_active set to True. If no password is provided, set_unusable_password() will be called. The extra_fields keyword arguments are passed through to the User’s __init__ method to allow setting arbitrary fields on a custom User model. See Creatin

forms.MultiWidget.render()

render(name, value, attrs=None) [source] Argument value is handled differently in this method from the subclasses of Widget because it has to figure out how to split a single value for display in multiple widgets. The value argument used when rendering can be one of two things: A list. A single value (e.g., a string) that is the “compressed” representation of a list of values. If value is a list, the output of render() will be a concatenation of rendered child widgets. If value is not a li

db.models.functions.Length

class Length(expression, **extra) [source] Accepts a single text field or expression and returns the number of characters the value has. If the expression is null, then the length will also be null. Usage example: >>> # Get the length of the name and goes_by fields >>> from django.db.models.functions import Length >>> Author.objects.create(name='Margaret Smith') >>> author = Author.objects.annotate( ... name_length=Length('name'), ... goes_by_length=

views.generic.dates.WeekMixin.week_format

week_format The strftime() format to use when parsing the week. By default, this is '%U', which means the week starts on Sunday. Set it to '%W' if your week starts on Monday.

db.backends.base.schema.BaseDatabaseSchemaEditor.add_field()

BaseDatabaseSchemaEditor.add_field(model, field) [source] Adds a column (or sometimes multiple) to the model’s table to represent the field. This will also add indexes or a unique constraint if the field has db_index=True or unique=True. If the field is a ManyToManyField without a value for through, instead of creating a column, it will make a table to represent the relationship. If through is provided, it is a no-op. If the field is a ForeignKey, this will also add the foreign key constrain

How to use Django with Gunicorn

Gunicorn (‘Green Unicorn’) is a pure-Python WSGI server for UNIX. It has no dependencies and is easy to install and use. Installing Gunicorn Installing gunicorn is as easy as pip install gunicorn. For more details, see the gunicorn documentation. Running Django in Gunicorn as a generic WSGI application When Gunicorn is installed, a gunicorn command is available which starts the Gunicorn server process. At its simplest, gunicorn just needs to be called with the location of a module containing a

gis.geos.MultiLineString

class MultiLineString(*args, **kwargs) MultiLineString objects may be instantiated by passing in LineString objects as arguments, or a single sequence of LineString objects: >>> ls1 = LineString((0, 0), (1, 1)) >>> ls2 = LineString((2, 2), (3, 3)) >>> mls = MultiLineString(ls1, ls2) >>> mls = MultiLineString([ls1, ls2]) Changed in Django 1.10: In previous versions, an empty MultiLineString couldn’t be instantiated. merged Returns a LineString represe

admin.ModelAdmin.date_hierarchy

ModelAdmin.date_hierarchy Set date_hierarchy to the name of a DateField or DateTimeField in your model, and the change list page will include a date-based drilldown navigation by that field. Example: date_hierarchy = 'pub_date' This will intelligently populate itself based on available data, e.g. if all the dates are in one month, it’ll show the day-level drill-down only. Note date_hierarchy uses QuerySet.datetimes() internally. Please refer to its documentation for some caveats when time