Using Django

Introductions to all the key parts of Django you’ll need to know: How to install Django Models and databases Handling HTTP requests Working with forms Templates Class-based views Migrations Managing files Testing in Django User authentication in Django Django’s cache framework Conditional View Processing Cryptographic signing Sending email Internationalization and localization Logging Pagination Porting to Python 3 Security in Django Performance and optimization Serializing Django objects Djang

db.migrations.operations.SeparateDatabaseAndState

class SeparateDatabaseAndState(database_operations=None, state_operations=None) [source] A highly specialized operation that let you mix and match the database (schema-changing) and state (autodetector-powering) aspects of operations. It accepts two list of operations, and when asked to apply state will use the state list, and when asked to apply changes to the database will use the database list. Do not use this operation unless you’re very sure you know what you’re doing.

db.models.Field.pre_save()

pre_save(model_instance, add) [source] Method called prior to get_db_prep_save() to prepare the value before being saved (e.g. for DateField.auto_now). model_instance is the instance this field belongs to and add is whether the instance is being saved to the database for the first time. It should return the value of the appropriate attribute from model_instance for this field. The attribute name is in self.attname (this is set up by Field). See Preprocessing values before saving for usage. F

contenttypes.models.ContentTypeManager.get_for_id()

get_for_id(id) Lookup a ContentType by ID. Since this method uses the same shared cache as get_for_model(), it’s preferred to use this method over the usual ContentType.objects.get(pk=id)

forms.Form.is_bound

Form.is_bound If you need to distinguish between bound and unbound form instances at runtime, check the value of the form’s is_bound attribute: >>> f = ContactForm() >>> f.is_bound False >>> f = ContactForm({'subject': 'hello'}) >>> f.is_bound True Note that passing an empty dictionary creates a bound form with empty data: >>> f = ContactForm({}) >>> f.is_bound True If you have a bound Form instance and want to change the data somehow,

gis.gdal.GDALRaster.width

width The width of the source in pixels (X-axis). >>> GDALRaster({'width': 10, 'height': 20, 'srid': 4326}).width 10

staticfiles.testing.StaticLiveServerTestCase

class testing.StaticLiveServerTestCase This unittest TestCase subclass extends django.test.LiveServerTestCase. Just like its parent, you can use it to write tests that involve running the code under test and consuming it with testing tools through HTTP (e.g. Selenium, PhantomJS, etc.), because of which it’s needed that the static assets are also published. But given the fact that it makes use of the django.contrib.staticfiles.views.serve() view described above, it can transparently overlay a

contenttypes.models.ContentTypeManager.get_for_models()

get_for_models(*models, for_concrete_models=True) Takes a variadic number of model classes, and returns a dictionary mapping the model classes to the ContentType instances representing them. for_concrete_models=False allows fetching the ContentType of proxy models.

gis.gdal.GDALRaster.extent

extent Extent (boundary values) of the raster source, as a 4-tuple (xmin, ymin, xmax, ymax) in the spatial reference system of the source. >>> rst = GDALRaster({'width': 10, 'height': 20, 'srid': 4326}) >>> rst.extent (0.0, -20.0, 10.0, 0.0) >>> rst.origin.x = 100 >>> rst.extent (100.0, -20.0, 110.0, 0.0)

http.HttpResponseBadRequest

class HttpResponseBadRequest [source] Acts just like HttpResponse but uses a 400 status code.