{"id":1040,"date":"2011-01-20T17:01:11","date_gmt":"2011-01-20T08:01:11","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=1040"},"modified":"2011-01-20T21:07:46","modified_gmt":"2011-01-20T12:07:46","slug":"django-%e3%83%95%e3%82%a9%e3%83%bc%e3%83%a0%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e5%88%b6%e5%be%a1%e3%83%95%e3%82%a3%e3%83%bc%e3%83%ab%e3%83%89%e3%82%92%e4%b8%8d%e5%8f%af%e8%a6%96%e3%81%ab%e3%81%99","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/1040","title":{"rendered":"Django \u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u3067\u5236\u5fa1\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4e0d\u53ef\u8996\u306b\u3059\u308b"},"content":{"rendered":"<p>\u30a4\u30ad\u30ca\u30ea\u95a2\u4fc2\u7121\u3044\u8a71\u3067\u3059\u304c\u3001\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306e\u4e8b\u3092\u6700\u521d\u306f\u300c\u8907\u6570\u7a2e\u985e\u306e\u300d\u30d5\u30a9\u30fc\u30e0\u3092\u307e\u3068\u3081\u3066\u6271\u3048\u308b\u3082\u306e\u3068\u601d\u3044\u8fbc\u3093\u3067\u3044\u307e\u3057\u305f\u3002<br \/>\n\u672c\u5f53\u306f\u300c1\u7a2e\u985e\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u8907\u6570\u300d\u307e\u3068\u3081\u3066\u6271\u3048\u308b\u3082\u306e\u3067\u3059\u3002<br \/>\n\u3053\u308c\u3067\u3061\u3087\u3063\u3068\u6642\u9593\u3092\u7121\u99c4\u306b\u3057\u307e\u3057\u305f\u3002\u307f\u306a\u3055\u3093\u3082\u304a\u6c17\u3092\u3064\u3051\u4e0b\u3055\u3044\u3002\uff08\u305d\u3093\u306a\u52d8\u9055\u3044\u3059\u308b\u4eba\u306f\u3044\u306a\u3044\u304bw\uff09<\/p>\n<p>\u3055\u3066\u672c\u984c\u3067\u3059\u3002<br \/>\n\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306f\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u751f\u6210\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom django import forms\r\nfrom django.forms.formsets import formset_factory\r\n\r\nclass TestForm(forms.Form):\r\n    title = forms.CharField(label = u'\u30bf\u30a4\u30c8\u30eb')\r\n\r\nTestFormSet = formset_factory(TestForm)\r\n<\/pre>\n<p>TestFormSet\u306f\u30af\u30e9\u30b9\u306a\u306e\u3067\u3001\u30d3\u30e5\u30fc\u306e\u30b3\u30fc\u30c9\u3068\u304b\u3067TestFormSet()\u3068\u3084\u308b\u3068\u5b9f\u969b\u306b\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u308f\u3051\u3067\u3059\u3002<br \/>\n\u3067\u3001\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306b\u306f\u8272\u3005\u3068\u4fbf\u5229\u306a\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3057\u3066\u3001\u305d\u306e\u4e2d\u306b\u9806\u5e8f\u3068\u524a\u9664\u30d5\u30e9\u30b0\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u30af\u30e9\u30b9\u3092\u751f\u6210\u3057\u3066\u308b\u90e8\u5206\u3092\u3061\u3087\u3063\u3068\u5909\u3048\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nTestFormSet = formset_factory(TestForm, can_order = True, can_delete = True)\r\n<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3068\u3001\u30da\u30fc\u30b8\u3067\u30d5\u30a9\u30fc\u30e0\u304c\u8868\u793a\u3055\u308c\u308b\u5834\u5408\u306b\u3001\u5404\u30ec\u30b3\u30fc\u30c9\u306b\u8ffd\u52a0\u3067\u9806\u5e8f\u306e\u305f\u3081\u306einput[type=text]\u3068\u524a\u9664\u30d5\u30e9\u30b0\u306e\u305f\u3081\u306einput[type=checkbox]\u304c\u8ffd\u52a0\u3067\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n\u3082\u3061\u308d\u3093\u8868\u793a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3066\u3053\u308c\u3089\u306e\u5236\u5fa1\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30c7\u30fc\u30bf\u304c\u30dd\u30b9\u30c8\u3055\u308c\u305f\u3068\u304d\u306b\u3001\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u3067\u3044\u3044\u611f\u3058\u306b\u64cd\u4f5c\u51fa\u6765\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u4fbf\u5229\u306a\u6a5f\u80fd\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u5236\u5fa1\u7528\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u3082\u308d\u51fa\u3057\u306a\u306e\u3067\u3001\u30a8\u30f3\u30c9\u30e6\u30fc\u30b6\u30fc\u7528\u306e\u30da\u30fc\u30b8\u3067\u306f\u4e3b\u306b\u898b\u305f\u76ee\u306e\u554f\u984c\u304b\u3089\u305d\u306e\u307e\u307e\u4f7f\u3046\u3063\u3066\u306e\u306f\u3042\u307e\u308a\u51fa\u6765\u306a\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\n\uff08\u305d\u3082\u305d\u3082\u305d\u3046\u3044\u3046\u5834\u9762\u3067\u4f7f\u3046\u3053\u3068\u306f\u60f3\u5b9a\u3055\u308c\u3066\u306a\u3044\u3089\u3057\u3044\u3067\u3059\u3002\uff09<\/p>\n<p>\u305d\u3046\u3044\u3046\u5834\u5408\u306f\u5236\u5fa1\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30e6\u30fc\u30b6\u30fc\u306b\u76f4\u63a5\u898b\u305b\u305a\u306b\u3001JavaScript\u3067\u3044\u3044\u611f\u3058\u306b\u5236\u5fa1\u3057\u3066\u3042\u3052\u308b\u306e\u304c\u3001\u3088\u304f\u3042\u308b\u30d1\u30bf\u30fc\u30f3\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306e\u5229\u4fbf\u6027\u3092\u6d3b\u304b\u3057\u3064\u3064\u305d\u3046\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u30b4\u30ea\u30b4\u30ea\u3068\u9811\u5f35\u308b\u3068\u304b\u3001CSS\u3084JavaScript\u3067\u9811\u5f35\u308b\u3068\u304b\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u304c\u3001\u305d\u3082\u305d\u3082\u5236\u5fa1\u30d5\u30a3\u30fc\u30eb\u30c9\u304chidden\u3067\u51fa\u529b\u3055\u308c\u3066\u304f\u308c\u308c\u3070\u4f55\u306e\u554f\u984c\u3082\u7121\u3044\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3084\u3063\u3066\u307f\u305f\u3089\u3046\u307e\u3044\u5177\u5408\u306b\u884c\u304d\u307e\u3057\u305f\u3002(Django v1.2)<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom django import forms\r\nfrom django.forms.formsets import BaseFormSet, ORDERING_FIELD_NAME, DELETION_FIELD_NAME, formset_factory\r\n\r\nclass TestForm(forms.Form):\r\n    title = forms.CharField(label = u'\u30bf\u30a4\u30c8\u30eb')\r\n\r\nclass HiddenControlFormSet(BaseFormSet):\r\n    def add_fields(self, form, index):\r\n        u&quot;&quot;&quot;\u5236\u5fa1\u7528\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4e0d\u53ef\u8996\u306b\u3059\u308b&quot;&quot;&quot;\r\n        BaseFormSet.add_fields(self, form, index)\r\n        if ORDERING_FIELD_NAME in form.fields:\r\n            form.fields&#x5B;ORDERING_FIELD_NAME].widget = forms.HiddenInput()\r\n        if DELETION_FIELD_NAME in form.fields:\r\n            form.fields&#x5B;DELETION_FIELD_NAME].widget = forms.HiddenInput()\r\n\r\nTestFormSet = formset_factory(TestForm,\r\n    formset = HiddenControlFormSet,\r\n    can_order = True,\r\n    can_delete = True,\r\n)\r\n<\/pre>\n<p>BaseFormSet\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u305fHiddenControlFormSet\u30af\u30e9\u30b9\u3092\u4f5c\u308aadd_field\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3001\u305d\u306e\u30af\u30e9\u30b9\u3092formset_factory\u306b\u6307\u5b9a\u3057\u3066\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30a4\u30ad\u30ca\u30ea\u95a2\u4fc2\u7121\u3044\u8a71\u3067\u3059\u304c\u3001\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306e\u4e8b\u3092\u6700\u521d\u306f\u300c\u8907\u6570\u7a2e\u985e\u306e\u300d\u30d5\u30a9\u30fc\u30e0\u3092\u307e\u3068\u3081\u3066\u6271\u3048\u308b\u3082\u306e\u3068\u601d\u3044\u8fbc\u3093\u3067\u3044\u307e\u3057\u305f\u3002<br \/>\n\u672c\u5f53\u306f\u300c1\u7a2e\u985e\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u8907\u6570\u300d\u307e\u3068\u3081\u3066\u6271\u3048\u308b\u3082\u306e\u3067\u3059\u3002<br \/>\n\u3053\u308c\u3067\u3061\u3087\u3063\u3068\u6642\u9593\u3092\u7121\u99c4\u306b\u3057\u307e\u3057\u305f\u3002\u307f\u306a\u3055\u3093\u3082\u304a\u6c17\u3092\u3064\u3051\u4e0b\u3055\u3044\u3002\uff08\u305d\u3093\u306a\u52d8\u9055\u3044\u3059\u308b\u4eba\u306f\u3044\u306a\u3044\u304bw\uff09<\/p>\n<p>\u3055\u3066\u672c\u984c\u3067\u3059\u3002<br \/>\n\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306f\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u751f\u6210\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom django import forms\r\nfrom django.forms.formsets import formset_factory\r\n\r\nclass TestForm(forms.Form):\r\n    title = forms.CharField(label = u'\u30bf\u30a4\u30c8\u30eb')\r\n\r\nTestFormSet = formset_factory(TestForm)\r\n<\/pre>\n<p>TestFormSet\u306f\u30af\u30e9\u30b9\u306a\u306e\u3067\u3001\u30d3\u30e5\u30fc\u306e\u30b3\u30fc\u30c9\u3068\u304b\u3067TestFormSet()\u3068\u3084\u308b\u3068\u5b9f\u969b\u306b\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u308f\u3051\u3067\u3059\u3002<br \/>\n\u3067\u3001\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306b\u306f\u8272\u3005\u3068\u4fbf\u5229\u306a\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3057\u3066\u3001\u305d\u306e\u4e2d\u306b\u9806\u5e8f\u3068\u524a\u9664\u30d5\u30e9\u30b0\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u30af\u30e9\u30b9\u3092\u751f\u6210\u3057\u3066\u308b\u90e8\u5206\u3092\u3061\u3087\u3063\u3068\u5909\u3048\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nTestFormSet = formset_factory(TestForm, can_order = True, can_delete = True)\r\n<\/pre>\n<p>\u3053\u3046\u3059\u308b\u3068\u3001\u30da\u30fc\u30b8\u3067\u30d5\u30a9\u30fc\u30e0\u304c\u8868\u793a\u3055\u308c\u308b\u5834\u5408\u306b\u3001\u5404\u30ec\u30b3\u30fc\u30c9\u306b\u8ffd\u52a0\u3067\u9806\u5e8f\u306e\u305f\u3081\u306einput[type=text]\u3068\u524a\u9664\u30d5\u30e9\u30b0\u306e\u305f\u3081\u306einput[type=checkbox]\u304c\u8ffd\u52a0\u3067\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n\u3082\u3061\u308d\u3093\u8868\u793a\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u304f\u3066\u3053\u308c\u3089\u306e\u5236\u5fa1\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30c7\u30fc\u30bf\u304c\u30dd\u30b9\u30c8\u3055\u308c\u305f\u3068\u304d\u306b\u3001\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u3067\u3044\u3044\u611f\u3058\u306b\u64cd\u4f5c\u51fa\u6765\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u4fbf\u5229\u306a\u6a5f\u80fd\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u5236\u5fa1\u7528\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u3082\u308d\u51fa\u3057\u306a\u306e\u3067\u3001\u30a8\u30f3\u30c9\u30e6\u30fc\u30b6\u30fc\u7528\u306e\u30da\u30fc\u30b8\u3067\u306f\u4e3b\u306b\u898b\u305f\u76ee\u306e\u554f\u984c\u304b\u3089\u305d\u306e\u307e\u307e\u4f7f\u3046\u3063\u3066\u306e\u306f\u3042\u307e\u308a\u51fa\u6765\u306a\u3044\u3067\u3057\u3087\u3046\u3002<br \/>\n\uff08\u305d\u3082\u305d\u3082\u305d\u3046\u3044\u3046\u5834\u9762\u3067\u4f7f\u3046\u3053\u3068\u306f\u60f3\u5b9a\u3055\u308c\u3066\u306a\u3044\u3089\u3057\u3044\u3067\u3059\u3002\uff09<\/p>\n<p>\u305d\u3046\u3044\u3046\u5834\u5408\u306f\u5236\u5fa1\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30e6\u30fc\u30b6\u30fc\u306b\u76f4\u63a5\u898b\u305b\u305a\u306b\u3001JavaScript\u3067\u3044\u3044\u611f\u3058\u306b\u5236\u5fa1\u3057\u3066\u3042\u3052\u308b\u306e\u304c\u3001\u3088\u304f\u3042\u308b\u30d1\u30bf\u30fc\u30f3\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u30d5\u30a9\u30fc\u30e0\u30bb\u30c3\u30c8\u306e\u5229\u4fbf\u6027\u3092\u6d3b\u304b\u3057\u3064\u3064\u305d\u3046\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u30b4\u30ea\u30b4\u30ea\u3068\u9811\u5f35\u308b\u3068\u304b\u3001CSS\u3084JavaScript\u3067\u9811\u5f35\u308b\u3068\u304b\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u304c\u3001\u305d\u3082\u305d\u3082\u5236\u5fa1\u30d5\u30a3\u30fc\u30eb\u30c9\u304chidden\u3067\u51fa\u529b\u3055\u308c\u3066\u304f\u308c\u308c\u3070\u4f55\u306e\u554f\u984c\u3082\u7121\u3044\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3084\u3063\u3066\u307f\u305f\u3089\u3046\u307e\u3044\u5177\u5408\u306b\u884c\u304d\u307e\u3057\u305f\u3002(Django v1.2)<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom django import forms\r\nfrom django.forms.formsets import BaseFormSet, ORDERING_FIELD_NAME, DELETION_FIELD_NAME, formset_factory\r\n\r\nclass TestForm(forms.Form):\r\n    title = forms.CharField(label = u'\u30bf\u30a4\u30c8\u30eb')\r\n\r\nclass HiddenControlFormSet(BaseFormSet):\r\n    def add_fields(self, form, index):\r\n        u&quot;&quot;&quot;\u5236\u5fa1\u7528\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4e0d\u53ef\u8996\u306b\u3059\u308b&quot;&quot;&quot;\r\n        BaseFormSet.add_fields(self, form, index)\r\n        if ORDERING_FIELD_NAME in form.fields:\r\n            form.fields&#x5B;ORDERING_FIELD_NAME].widget = forms.HiddenInput()\r\n        if DELETION_FIELD_NAME in form.fields:\r\n            form.fields&#x5B;DELETION_FIELD_NAME].widget = forms.HiddenInput()\r\n\r\nTestFormSet = formset_factory(TestForm,\r\n    formset = HiddenControlFormSet,\r\n    can_order = True,\r\n    can_delete = True,\r\n)\r\n<\/pre>\n<p>BaseFormSet\u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u305fHiddenControlFormSet\u30af\u30e9\u30b9\u3092\u4f5c\u308aadd_field\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3001\u305d\u306e\u30af\u30e9\u30b9\u3092formset_factory\u306b\u6307\u5b9a\u3057\u3066\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[369,60],"class_list":["post-1040","post","type-post","status-publish","format-standard","hentry","category-tech","tag-django","tag-python"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=1040"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1040\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=1040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=1040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=1040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}