Writing your first Django app, part 5

This tutorial begins where Tutorial 4 left off. We’ve built a Web-poll application, and we’ll now create some automated tests for it. Introducing automated testing What are automated tests? Tests are simple routines that check the operation of your code. Testing operates at different levels. Some tests might apply to a tiny detail (does a particular model method return values as expected?) while others examine the overall operation of the software (does a sequence of user inputs on the site pro

Unicode data

Django natively supports Unicode data everywhere. Providing your database can somehow store the data, you can safely pass around Unicode strings to templates, models and the database. This document tells you what you need to know if you’re writing applications that use data or templates that are encoded in something other than ASCII. Creating the database Make sure your database is configured to be able to store arbitrary string data. Normally, this means giving it an encoding of UTF-8 or UTF-1

http.HttpResponse.getvalue()

HttpResponse.getvalue() [source] Returns the value of HttpResponse.content. This method makes an HttpResponse instance a stream-like object.

admin.AdminSite.register()

AdminSite.register(model_or_iterable, admin_class=None, **options) [source] Registers the given model class (or iterable of classes) with the given admin_class. admin_class defaults to ModelAdmin (the default admin options). If keyword arguments are given – e.g. list_display – they’ll be applied as options to the admin class. Raises ImproperlyConfigured if a model is abstract. and django.contrib.admin.sites.AlreadyRegistered if a model is already registered.

sitemaps.Sitemap.priority

priority Optional. Either a method or attribute. If it’s a method, it should take one argument – an object as returned by items() – and return that object’s priority as either a string or float. If it’s an attribute, its value should be either a string or float representing the priority of every object returned by items(). Example values for priority: 0.4, 1.0. The default priority of a page is 0.5. See the sitemaps.org documentation for more.

sitemaps.Sitemap.limit

limit Optional. This attribute defines the maximum number of URLs included on each page of the sitemap. Its value should not exceed the default value of 50000, which is the upper limit allowed in the Sitemaps protocol.

core.files.uploadhandler.FileUploadHandler.new_file()

FileUploadHandler.new_file(field_name, file_name, content_type, content_length, charset, content_type_extra) [source] Callback signaling that a new file upload is starting. This is called before any data has been fed to any upload handlers. field_name is a string name of the file <input> field. file_name is the unicode filename that was provided by the browser. content_type is the MIME type provided by the browser – E.g. 'image/jpeg'. content_length is the length of the image given by

db.models.Model.full_clean()

Model.full_clean(exclude=None, validate_unique=True) [source] This method calls Model.clean_fields(), Model.clean(), and Model.validate_unique() (if validate_unique is True), in that order and raises a ValidationError that has a message_dict attribute containing errors from all three stages. The optional exclude argument can be used to provide a list of field names that can be excluded from validation and cleaning. ModelForm uses this argument to exclude fields that aren’t present on your fo

views.generic.dates.WeekMixin

class WeekMixin [source] A mixin that can be used to retrieve and provide parsing information for a week component of a date. Methods and Attributes 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. week Optional The value for the week, as a string. By default, set to None, which means the week will be determined using other means. get_week_format() [sourc

db.transaction.non_atomic_requests()

non_atomic_requests(using=None) [source] This decorator will negate the effect of ATOMIC_REQUESTS for a given view: from django.db import transaction @transaction.non_atomic_requests def my_view(request): do_stuff() @transaction.non_atomic_requests(using='other') def my_other_view(request): do_stuff_on_the_other_database() It only works if it’s applied to the view itself.