db.models.Model.clean()

Model.clean() [source] This method should be used to provide custom model validation, and to modify attributes on your model if desired. For instance, you could use it to automatically provide a value for a field, or to do validation that requires access to more than a single field: import datetime from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import ugettext_lazy as _ class Article(models.Model): ... def clean(self):

admin.InlineModelAdmin.max_num

InlineModelAdmin.max_num This controls the maximum number of forms to show in the inline. This doesn’t directly correlate to the number of objects, but can if the value is small enough. See Limiting the number of editable objects for more information. InlineModelAdmin.get_max_num() also allows you to customize the maximum number of extra forms.

gis.db.models.functions.AsKML

class AsKML(expression, precision=8, **extra) Availability: PostGIS, SpatiaLite Accepts a single geographic field or expression and returns a Keyhole Markup Language (KML) representation of the geometry. Example: >>> qs = Zipcode.objects.annotate(kml=AsKML('poly')) >>> print(qs[0].kml) <Polygon><outerBoundaryIs><LinearRing><coordinates>-103.04135,36.217596,0 ... -103.04135,36.217596,0</coordinates></LinearRing></outerBoundaryIs><

auth.decorators.user_passes_test()

user_passes_test(test_func, login_url=None, redirect_field_name='next') [source] As a shortcut, you can use the convenient user_passes_test decorator which performs a redirect when the callable returns False: from django.contrib.auth.decorators import user_passes_test def email_check(user): return user.email.endswith('@example.com') @user_passes_test(email_check) def my_view(request): ... user_passes_test() takes a required argument: a callable that takes a User object and returns

auth.mixins.UserPassesTestMixin.get_test_func()

get_test_func() You can also override the get_test_func() method to have the mixin use a differently named function for its checks (instead of test_func()). Stacking UserPassesTestMixin Due to the way UserPassesTestMixin is implemented, you cannot stack them in your inheritance list. The following does NOT work: class TestMixin1(UserPassesTestMixin): def test_func(self): return self.request.user.email.endswith('@example.com') class TestMixin2(UserPassesTestMixin): def test_

forms.models.modelform_factory()

modelform_factory(model, form=ModelForm, fields=None, exclude=None, formfield_callback=None, widgets=None, localized_fields=None, labels=None, help_texts=None, error_messages=None, field_classes=None) [source] Returns a ModelForm class for the given model. You can optionally pass a form argument to use as a starting point for constructing the ModelForm. fields is an optional list of field names. If provided, only the named fields will be included in the returned fields. exclude is an optiona

db.models.BooleanField

class BooleanField(**options) [source] A true/false field. The default form widget for this field is a CheckboxInput. If you need to accept null values then use NullBooleanField instead. The default value of BooleanField is None when Field.default isn’t defined.

core.files.uploadedfile.UploadedFile.name

UploadedFile.name The name of the uploaded file (e.g. my_file.txt).

forms.MultipleHiddenInput.choices

choices This attribute is optional when the form field does not have a choices attribute. If it does, it will override anything you set here when the attribute is updated on the Field.

forms.FilePathField.recursive

recursive If False (the default) only the direct contents of path will be offered as choices. If True, the directory will be descended into recursively and all descendants will be listed as choices.