... ようにしたいと思うかもしれません。 ArticleForm からフォームセットを作るには、次のようにします: >>> from django.forms import formset_factory >>> ArticleFormSet = formset_factory ( ArticleForm ) これで ArticleFormSet という名前のフォームセットクラスが作成さ ... ームセットをインスタンス化することで、フォームセット内のフォームをイテレートし、通常のフォームと同じように表示できます: >>> formset = ArticleFormSet () >>> for form in formset : ... print ( form ) ... <div><label for="id_form-0-title">Title:</label><inpu ... おり、空のフォームがひとつだけ表示されました。表示される空のフォームの数は extra パラメータで制御できます。デフォルトでは、 formset_factory() は空のフォームを1つ定義します。次の例では、フォームセットクラスを作成して空のフォームを2つ表示します: >>> Articl ... ... validate_min = False , absolute_max = None , can_delete_extra = True , renderer = None ) [ソース] 与えられた form クラスの FormSet クラスを返します。 使用例は フォームセット を見てください。 ... ... _factory ( Author , form = AuthorForm , localized_fields = [ "birth_date" ]) モデルのフォームセット class models. BaseModelFormSet 通常のフォームセット のように、 Django は Django モデルでの作業をより便利にするために、いくつかの拡張 フォームセットクラス ... を提供しています。上の Author モデルを再利用してみましょう: >>> from django.forms import modelformset_factory >>> from myapp.models import Author >>> AuthorFormSet = modelformset_factory ( Author , fields = [ "name" , "title ... だけを使うように制限されます。または、除外するフィールドを指定する "オプトアウト" アプローチをとることもできます: >>> AuthorFormSet = modelformset_factory ( Author , exclude = [ "birth_date" ]) これは Author モデルに関連付けられたデータを扱うことができる ... ... す。 event.detail.formsetName は行が属するフォームセットを示します。 formset:added イベントでは、 event.target は新しく追加された行です。 カスタムの ... html' %} {% load static %} {% block admin_change_form_document_ready %} {{ block .super }} < script src = " {% static 'app/formset_handlers.js' %} " ></ script > {% endblock %} app/static/app/formset_handlers.js document . addEventListener ( 'formset:ad ... ded' , ( event ) => { if ( event . detail . formsetName == 'author_set' ) { // Do something } }); document . addEventListener ( 'formset:removed' , ( event ) => { // Row remo ... ... form, like {{ form }} in a template, from Django 5.0. In order to ease adopting the new output style, the default form and formset templates are now configurable at the project level via the FORM_RENDERER setting. See the Forms section (below) for full ... overridden with a string value to specify the template name per-form class. Similarly, the default template used to render formsets can be specified via the matching formset_template_name renderer attribute. The new div.html form template, referencing F ... output style is not appropriate for your project, you should define a renderer subclass specifying form_template_name and formset_template_name for your required style, and set FORM_RENDERER accordingly. For example, for the <p> output style used by as ... ... フィールドを選択する を参照してください。使うフィールドの定義を省略すると、 ImproperlyConfigured 例外を引き起こします。 modelformset_factory modelformset_factory ( model , form = ModelForm , formfield_callback = None , formset = BaseModelFormSet , extra = ... te_max = None , can_delete_extra = True , renderer = None , edit_only = False ) [ソース] 与えられた model クラスに対して、 FormSet クラスを返します。 引数 model 、 form 、 fields 、 exclude 、 formfield_callback 、 widgets 、 localized_fields 、 labels ... 、 help_texts 、 error_messages 、 field_classes は、すべて modelform_factory() を通して引き渡されます。 引数 formset , extra , can_delete , can_order , max_num , validate_max , min_num , validate_min , absolute_max , can_delete_extra , およ ... ... if you feed your own XML documents to the loaddata management command, you will need to ensure they do not contain a DTD. Formset memory exhaustion Previous versions of Django did not validate or limit the form-count data provided by the client in a fo ... possible to exhaust a server's available memory by forcing it to create very large numbers of forms. In Django 1.3.6, all formsets have a strictly-enforced maximum number of forms (1000 by default, though it can be set higher via the max_num formset fa ... ... if you feed your own XML documents to the loaddata management command, you will need to ensure they do not contain a DTD. Formset memory exhaustion Previous versions of Django did not validate or limit the form-count data provided by the client in a fo ... possible to exhaust a server's available memory by forcing it to create very large numbers of forms. In Django 1.4.4, all formsets have a strictly-enforced maximum number of forms (1000 by default, though it can be set higher via the max_num formset fa ... ... れら自身のカスタムウィジェットを暗示するからです。 ModelAdmin. inlines 後述の InlineModelAdmin オブジェクトと ModelAdmin.get_formsets_with_inlines() を参照してください。 ModelAdmin. list_display admin のチェンジリストページでどのフィールドを表示するかコン ... をオーバーライドすると、"選択したオブジェクトの削除" アクション に対する削除のプロセスをカスタムできます。 ModelAdmin. save_formset ( request , form , formset , change ) [ソース] save_formset メソッドには、 HttpRequest 、親 ModelForm のインスタンス、親オ ... のインスタンスそれぞれに request.user を追加するには、次のようにします。 class ArticleAdmin ( admin . ModelAdmin ): def save_formset ( self , request , form , formset , change ): instances = formset . save ( commit = False ) for obj in formset . deleted_o ... ... include Armed Forces postal codes. This is backwards-incompatible if you were relying on USStateField not including them. FormSet updates In Django 1.3 FormSet creation behavior is modified slightly. Historically the class didn't make a distinction bet ... This was inconsistent with behavior in other parts of the framework. Starting with 1.3 if you pass in empty dictionary the FormSet will raise a ValidationError . 以下は FormSet を使用した例です。 >>> class ArticleForm ( Form ): ... title = CharField () ... ... pub_date = DateField () ... >>> ArticleFormSet = formset_factory ( ArticleForm ) 以下のコードでは ValidationError が発生します。 >>> ArticleFormSet ({}) Traceback (most ... 2026年10月08日