{"id":505,"date":"2013-07-21T21:05:32","date_gmt":"2013-07-22T01:05:32","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/acts\/?p=505"},"modified":"2013-07-21T21:05:32","modified_gmt":"2013-07-22T01:05:32","slug":"django-formsets-the-worst-thing-ever","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/acts\/2013\/07\/21\/django-formsets-the-worst-thing-ever\/","title":{"rendered":"Django Formsets, the worst thing ever?"},"content":{"rendered":"<p>This kind of thing really attracted me to django, but then the usability of it goes entirely out the window when you take a closer look.<\/p>\n<p>Formsets are basically a container for an arbitrary collection of forms. A form is a abstraction layer for UI, but I&#8217;ve seen they (or rather ModelForms) can be somewhat helpful as a funnel for POST vars and validation of the model. Maybe my issue is that the use I&#8217;ve found for them is not the primary concern people have.<\/p>\n<p>from https:\/\/docs.djangoproject.com\/en\/dev\/topics\/forms\/formsets\/<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt; ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet)\r\n&gt;&gt;&gt; data = {\r\n...     &#039;form-TOTAL_FORMS&#039;: u&#039;2&#039;,\r\n...     &#039;form-INITIAL_FORMS&#039;: u&#039;0&#039;,\r\n...     &#039;form-MAX_NUM_FORMS&#039;: u&#039;&#039;,\r\n...     &#039;form-0-title&#039;: u&#039;Test&#039;,\r\n...     &#039;form-0-pub_date&#039;: u&#039;1904-06-16&#039;,\r\n...     &#039;form-1-title&#039;: u&#039;Test&#039;,\r\n...     &#039;form-1-pub_date&#039;: u&#039;1912-06-23&#039;,\r\n... }\r\n&gt;&gt;&gt; formset = ArticleFormSet(data)\r\n&gt;&gt;&gt; formset.is_valid()\r\n<\/pre>\n<p>See, how you would expect something like this to work is it would take in a list, or at least a dict with a list. But no, they have you cat &#8220;form-n-&#8221; to the field name. This is just so sloppy I have to point it out.<\/p>\n<p>They spent so much time figuring out how to take away customizability from the front end, they weren&#8217;t paying attention to the backend.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This kind of thing really attracted me to django, but then the usability of it goes entirely out the window when you take a closer look. Formsets are basically a container for an arbitrary collection of forms. A form is a abstraction layer for UI, but I&#8217;ve seen they (or rather ModelForms) can be somewhat [&hellip;]<\/p>\n","protected":false},"author":4571,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63924,64008],"tags":[111222,50627,64075,64076,64719,64074,64077,5464],"class_list":["post-505","post","type-post","status-publish","format-standard","hentry","category-atg","category-flashcards","tag-dict","tag-django","tag-form","tag-formset","tag-list","tag-model","tag-modelform","tag-python"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/users\/4571"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/comments?post=505"}],"version-history":[{"count":2,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/505\/revisions"}],"predecessor-version":[{"id":507,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/505\/revisions\/507"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/media?parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/categories?post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/tags?post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}