Hacker News new | ask | show | jobs
by mattchew 4755 days ago
I don't like Forms/ModelForms.

It doesn't seem to be a common complaint, but I always end up fighting with Forms when I try to use them. Too complicated, too confining, and too unique-to-Django. I wish Django had gone with field helpers instead.

4 comments

For a big subset of stuff, the Django forms are perfectly fine once you grok what they do, but in recent years, I've usually supplemented them with CrispyForms [1] (used to django-uni-form) and FloppyForms [2] --either individually or in combo-- for extra form flexibility.

[1] https://github.com/maraujop/django-crispy-forms

[2] https://github.com/brutasse/django-floppyforms

I'm curious about 'field helpers,' can you point to a page or briefly describe the difference?
Sure, I mean helpers for the template/view that make it easier (syntax, data binding, validations) to render a HTML form widget. Instead of defining your form as a unit in app code, you manage the form fields in the view/template. For my money, this is much more intuitive and flexible.

It's common in other web frameworks. At least Codeigniter, Ruby on Rails, and ASP.NET MVC use this approach:

http://ellislab.com/codeigniter/user-guide/helpers/form_help...

http://guides.rubyonrails.org/form_helpers.html

http://msdn.microsoft.com/en-us/library/dd410596(v=vs.100).a...

Not 100% sure this is what mattchew was talking about, but instead of defining the form and then rendering the form field by doing something like this:

> {{ form.thefield }}

You would instead simply define the model and render the form field with something like this:

> {{ model.thefield | render_input }}

Or, if you had a regular Form (i.e. not a ModelForm) you would do something like this:

> {{ render_input:name="field_name" }}

And if you wanted validation or something, you'd need to create your own render_* methods to perform that validation.

Really? I find that to be one of Django's biggest wins for me. The only thing I dislike about it is that you need to use multiple forms if you need to wrap multiple models. But having forms that aren't tied to a model is so easy in Django.
If it makes you feel better, you're not the only one.