djangodocs.org

669 sections in Django 5.1 Search all versions →

Validating objects

Reference Model instance reference

… as a whole - Model.clean() Validate the field uniqueness - Model.validate_unique() Validate the constraints - Model.validate_constraints() All four steps are performed when you call a model’s full_clean() method. When you use a ModelForm, the call to is_valid() will perform these …

Validating objects

Reference Model instance reference

class Article(models.Model): ... To assign exceptions to a specific field, instantiate the ValidationError with a dictionary, where the keys are the field names.

Field types

Topic guide Models Fields

INTEGER, VARCHAR, TEXT). The default HTML widget to use when rendering a form field (e.g. <input type="text">, <select>). The minimal validation requirements, used in Django’s admin and in automatically-generated forms.

Topic guide Creating forms from models Model formsets

Just like with ModelForms, by default the clean() method of a ModelFormSet will validate that none of the items in the formset violate the unique constraints on your model (either unique, unique_together or unique_for_date|month|year).

ModelAdmin methods

Reference The Django admin site ModelAdmin objects

ModelAdmin.formfield_for_manytomany(db_field,request,**kwargs) : Like the formfield_for_foreignkey method, the formfield_for_manytomany method can be overridden to change the default formfield for a many to many field.

Topic guide Translation Internationalization: in Python codeWorking with lazy translation objects

When using lazy translation for a plural string (n[p]gettext_lazy), you generally don’t know the number argument at the time of the string definition. Therefore, you are authorized to pass a key name instead of an integer as the number argument.

How it works

Reference Cross Site Request Forgery protection

2. A hidden form field with the name ‘csrfmiddlewaretoken’, present in all outgoing POST forms. In order to protect against BREACH attacks, the value of this field is not simply the secret.

Built-in forms

Topic guide Using the Django authentication system Authentication in web requests

If you don’t want to use the built-in views, but want the convenience of not having to write forms for this functionality, the authentication system provides several built-in forms located in django.contrib.auth.forms: NOTE: The built-in authentication forms make certain assumptions …

Topic guide Formsets

The max_num parameter to formset_factory() gives you the ability to limit the number of forms the formset will display: If the value of max_num is greater than the number of existing items in the initial data, up to extra additional …

Topic guide Creating forms from models ModelForm

… you can do so by defining the field declaratively and setting its validators parameter: NOTE: When you explicitly instantiate a form field like this, it is important to > understand how ModelForm and regular Form are related. ModelForm is a …

Using Django

Topic guide

… Apache and mod_wsgi Get your database running Install the Django code Models and databases Models Making queries Aggregation Search Managers Performing raw SQL queries Database transactions Multiple databases Tablespaces Database access optimization Database instrumentation Fixtures Examples of model relationship API …

N

Index

… - naturaltime - template filter - NEVER (ModelAdmin.ShowFacets attribute) - never_cache() (in module django.views.decorators.cache) - new_file() (FileUploadHandler method) - new_objects (models.BaseModelFormSet attribute) - next_page (LoginView attribute) - (LogoutView attribute) - next_page_number() (Page method) - ngettext() (in module django.utils.translation) - ngettext_lazy() …

ModelAdmin options

Reference The Django admin site ModelAdmin objects

ModelAdmin.form : By default a ModelForm is dynamically created for your model. It is used to create the form presented on both the add/change pages.

Topic guide Models FieldsRelationships

If you have more than one foreign key and through_fields is not specified, a validation error will be raised. A similar restriction applies to the foreign key to the target model (this would be Person in our example).

Topic guide Sending email

Header injection is a security exploit in which an attacker inserts extra email headers to control the “To:” and “From:” in email messages that your scripts generate.

C

Index

… setting - CACHES-TIMEOUT - setting - CACHES-VERSION - setting - CallbackFilter (class in django.utils.log) - callproc() (CursorWrapper method) - can_delete (BaseFormSet attribute) - (InlineModelAdmin attribute) - can_delete_extra (BaseFormSet attribute) - can_order (BaseFormSet attribute) - capfirst - template filter - captured_kwargs …

P

Index

… - PASSWORD - setting - password (models.User attribute) - password_change_done_template (AdminSite attribute) - password_change_template (AdminSite attribute) - password_changed() (in module django.contrib.auth.password_validation) - PASSWORD_HASHERS - setting - PASSWORD_RESET_TIMEOUT - setting - password_validators_help_text_html() (in module django.contrib.auth.password_validation) - password_validators_help_texts() (in module django.contrib.auth.password_validation) - …

U

Index

… - template filter | - urlencode() (in module django.utils.http) - (QueryDict method) - URLField (class in django.db.models) - (class in django.forms) - URLInput (class in django.forms) - urlize - template filter - urlizetrunc - template filter - urls - definitive …

Python Module Index

| | | django.contrib.auth | Django's authentication framework. | | | django.contrib.auth.backends | Django's built-in authentication backend classes. | | | django.contrib.auth.forms | | | | django.contrib.auth.hashers | | | | django.contrib.auth.middleware | Authentication middleware.