auth.models.User.set_password()

set_password(raw_password) Sets the user’s password to the given raw string, taking care of the password hashing. Doesn’t save the User object. When the raw_password is None, the password will be set to an unusable password, as if set_unusable_password() were used.

Many-to-one relationships

To define a many-to-one relationship, use ForeignKey: from django.db import models class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) email = models.EmailField() def __str__(self): # __unicode__ on Python 2 return "%s %s" % (self.first_name, self.last_name) class Article(models.Model): headline = models.CharField(max_length=100) pub_date = models.DateField() reporter = models.

gis.admin.GeoModelAdmin.map_width

map_width Width of the map, in pixels. Defaults to 600.

utils.safestring.SafeUnicode

class SafeUnicode Historical name of SafeText. Only available under Python 2.

gis.gdal.GDALRaster.origin

origin Coordinates of the top left origin of the raster in the spatial reference system of the source, as a point object with x and y members. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.origin [0.0, 0.0] >>> rst.origin.x = 1 >>> rst.origin [1.0, 0.0]

contrib packages

Django aims to follow Python’s “batteries included” philosophy. It ships with a variety of extra, optional tools that solve common Web-development problems. This code lives in django/contrib in the Django distribution. This document gives a rundown of the packages in contrib, along with any dependencies those packages have. Note For most of these add-ons – specifically, the add-ons that include either models or template tags – you’ll need to add the package name (e.g., 'django.contrib.redirect

forms.TimeInput

class TimeInput [source] Time input as a simple text box: <input type='text' ...> Takes same arguments as TextInput, with one more optional argument: format The format in which this field’s initial value will be displayed. If no format argument is provided, the default format is the first format found in TIME_INPUT_FORMATS and respects Format localization. For the treatment of microseconds, see DateTimeInput.

forms.ChoiceField.choices

choices Either an iterable (e.g., a list or tuple) of 2-tuples to use as choices for this field, or a callable that returns such an iterable. This argument accepts the same formats as the choices argument to a model field. See the model field reference documentation on choices for more details. If the argument is a callable, it is evaluated each time the field’s form is initialized.

views.generic.dates.DayMixin.get_previous_day()

get_previous_day(date) [source] Returns a date object containing the previous valid day. This function can also return None or raise an Http404 exception, depending on the values of allow_empty and allow_future.

urls.get_script_prefix()

get_script_prefix() [source] Normally, you should always use reverse() to define URLs within your application. However, if your application constructs part of the URL hierarchy itself, you may occasionally need to generate URLs. In that case, you need to be able to find the base URL of the Django project within its Web server (normally, reverse() takes care of this for you). In that case, you can call get_script_prefix(), which will return the script prefix portion of the URL for your Django