mixinを編集するLink to this heading
以下のmixinは、Djangoの編集ビューを構築するのに使用されます。
FormMixinLink to this heading
- class django.views.generic.edit.FormMixinLink to this definition
フォームを作成したり表示したりする機能を提供するmixinクラス。
ミックスイン
メソッドと属性
- initialLink to this definition
フォームの初期化データのディクショナリ。
- form_classLink to this definition
インスタンス化するフォームクラス。
- success_urlLink to this definition
フォームが正常に処理されたときにリダイレクトするURL。
- prefixLink to this definition
The
prefixfor the generated form.
- get_initial()Link to this definition
Retrieve initial data for the form. By default, returns a copy of
initial.
- get_form_class()Link to this definition
Retrieve the form class to instantiate. By default
form_class.
- get_form(form_class=None)Link to this definition
Instantiate an instance of
form_classusingget_form_kwargs(). Ifform_classisn't providedget_form_class()will be used.
- get_form_kwargs()Link to this definition
フォームのインスタンス化に必要なキーワード引数を構築します。
The
initialargument is set toget_initial(). If the request is aPOSTorPUT, the request data (request.POSTandrequest.FILES) will also be provided.
- get_prefix()Link to this definition
Determine the
prefixfor the generated form. Returnsprefixby default.
- get_success_url()Link to this definition
Determine the URL to redirect to when the form is successfully validated. Returns
success_urlby default.
- form_valid(form)Link to this definition
Redirects to
get_success_url().
- form_invalid(form)Link to this definition
Renders a response, providing the invalid form as context.
- get_context_data(**kwargs)Link to this definition
Calls
get_form()and adds the result to the context data with the name 'form'.
ModelFormMixinLink to this heading
- class django.views.generic.edit.ModelFormMixinLink to this definition
A form mixin that works on
ModelForms, rather than a standalone form.Since this is a subclass of
SingleObjectMixin, instances of this mixin have access to themodelandquerysetattributes, describing the type of object that theModelFormis manipulating.If you specify both the
fieldsandform_classattributes, anImproperlyConfiguredexception will be raised.ミックスイン
メソッドと属性
- modelLink to this definition
A model class. Can be explicitly provided, otherwise will be determined by examining
self.objectorqueryset.
- fieldsLink to this definition
A list of names of fields. This is interpreted the same way as the
Meta.fieldsattribute ofModelForm.This is a required attribute if you are generating the form class automatically (e.g. using
model). Omitting this attribute will result in anImproperlyConfiguredexception.
- success_urlLink to this definition
フォームが正常に処理されたときにリダイレクトするURL。
success_urlmay contain dictionary string formatting, which will be interpolated against the object's field attributes. For example, you could usesuccess_url="/polls/{slug}/"to redirect to a URL composed out of theslugfield on a model.
- get_form_class()Link to this definition
Retrieve the form class to instantiate. If
form_classis provided, that class will be used. Otherwise, aModelFormwill be instantiated using the model associated with thequeryset, or with themodel, depending on which attribute is provided.
- get_form_kwargs()Link to this definition
Add the current instance (
self.object) to the standardget_form_kwargs().
- get_success_url()Link to this definition
Determine the URL to redirect to when the form is successfully validated. Returns
django.views.generic.edit.ModelFormMixin.success_urlif it is provided; otherwise, attempts to use theget_absolute_url()of the object.
- form_valid(form)Link to this definition
Saves the form instance, sets the current object for the view, and redirects to
get_success_url().
- form_invalid(form)Link to this definition
Renders a response, providing the invalid form as context.
ProcessFormViewLink to this heading
- class django.views.generic.edit.ProcessFormViewLink to this definition
A mixin that provides basic HTTP GET and POST workflow.
Extends
メソッドと属性
- get(request, *args, **kwargs)Link to this definition
Renders a response using a context created with
get_context_data().
- post(request, *args, **kwargs)Link to this definition
Constructs a form, checks the form for validity, and handles it accordingly.
- put(*args, **kwargs)Link to this definition
The
PUTaction is also handled and passes all parameters through topost().
DeletionMixinLink to this heading
- class django.views.generic.edit.DeletionMixinLink to this definition
Enables handling of the
DELETEHTTP action.メソッドと属性
- success_urlLink to this definition
The url to redirect to when the nominated object has been successfully deleted.
success_urlmay contain dictionary string formatting, which will be interpolated against the object's field attributes. For example, you could usesuccess_url="/parent/{parent_id}/"to redirect to a URL composed out of theparent_idfield on a model.
- delete(request, *args, **kwargs)Link to this definition
Retrieves the target object and calls its
delete()method, then redirects to the success URL.
- get_success_url()Link to this definition
Returns the url to redirect to when the nominated object has been successfully deleted. Returns
success_urlby default.