utils.translation.ungettext_lazy()

ungettext_lazy(singular, plural, number) [source]

forms.Widget.format_value()

format_value(value) Cleans and returns a value for use in the widget template. value isn’t guaranteed to be valid input, therefore subclass implementations should program defensively. Changed in Django 1.10: In older versions, this method is a private API named _format_value(). The old name will work until Django 2.0.

admin.ModelAdmin.get_changelist_form()

ModelAdmin.get_changelist_form(request, **kwargs) [source] Returns a ModelForm class for use in the Formset on the changelist page. To use a custom form, for example: from django import forms class MyForm(forms.ModelForm): pass class MyModelAdmin(admin.ModelAdmin): def get_changelist_form(self, request, **kwargs): return MyForm Note If you define the Meta.model attribute on a ModelForm, you must also define the Meta.fields attribute (or the Meta.exclude attribute). Howeve

auth.models.BaseUserManager.make_random_password()

make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789') Returns a random password with the given length and given string of allowed characters. Note that the default value of allowed_chars doesn’t contain letters that can cause user confusion, including: i, l, I, and 1 (lowercase letter i, lowercase letter L, uppercase letter i, and the number one) o, O, and 0 (lowercase letter o, uppercase letter o, and zero)

Custom Lookups

Django offers a wide variety of built-in lookups for filtering (for example, exact and icontains). This documentation explains how to write custom lookups and how to alter the working of existing lookups. For the API references of lookups, see the Lookup API reference. A simple lookup example Let’s start with a simple custom lookup. We will write a custom lookup ne which works opposite to exact. Author.objects.filter(name__ne='Jack') will translate to the SQL: "author"."name" <> 'Jack' T

core.files.File.file

file The underlying file object that this class wraps. Be careful with this attribute in subclasses. Some subclasses of File, including ContentFile and FieldFile, may replace this attribute with an object other than a Python file object. In these cases, this attribute may itself be a File subclass (and not necessarily the same subclass). Whenever possible, use the attributes and methods of the subclass itself rather than the those of the subclass’s file attribute.

db.models.DateField.auto_now

DateField.auto_now Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override. The field is only automatically updated when calling Model.save(). The field isn’t updated when making updates to other fields in other ways such as QuerySet.update(), though you can specify a custom value for the field in an update like that.

http.StreamingHttpResponse.streaming

StreamingHttpResponse.streaming This is always True.

forms.Form.is_multipart()

Form.is_multipart() If you’re writing reusable views or templates, you may not know ahead of time whether your form is a multipart form or not. The is_multipart() method tells you whether the form requires multipart encoding for submission: >>> f = ContactFormWithMugshot() >>> f.is_multipart() True Here’s an example of how you might use this in a template: {% if form.is_multipart %} <form enctype="multipart/form-data" method="post" action="/foo/"> {% else %}

admin.ModelAdmin.save_as_continue

ModelAdmin.save_as_continue New in Django 1.10. When save_as=True, the default redirect after saving the new object is to the change view for that object. If you set save_as_continue=False, the redirect will be to the changelist view. By default, save_as_continue is set to True.