4 ms·
When I used it (forms), it sure seemed powerful in idea, but I ended up with a ridiculous amount of code to generate dynamic forms (different field types depend
by cujo 13y ago
When I used it (forms), it sure seemed powerful in idea, but I ended up with a ridiculous amount of code to generate dynamic forms (different field types depending on the object instance).
I will safely assume that as a beginner I was missing some part of the puzzle, but I was never able to track down a good way to do it. Oh well.
- Daishiman 13y agoWell, StackOverflow helps a lot there. The important thing is that the process is standardized and fairly uniform. If you're using a lot of code to generate forms that depend on models, look into ModelForms: they allow you to generate a form that maps to a specific model's fields trivially and allow adding additional validation and persisting the model to the database.
- mildtrepidation 13y agoHow useful Django's forms are (and which ones to use) varies widely based on your requirements. I've had projects where the combination of the UI I had to work with and the data that was being manipulated required Form classes to be built and validated manually. Right now I'm working on a project with a fairly complex data set, but everything is falling beautifully into place with generic ModelForms created implicitly via FormViews with only minor tweaking to field visibility. It took me a while to get a solid handle on them, but Django usually does forms very well. The best case is that your UI requirements are fairly loose, otherwise it's likely you'll end up with mostly-custom HTML, but even then you still have the potential to save a lot of Python code with things like ModelForms and/or FormViews.
- cdjk 13y agoDynamic forms in django are difficult. Personally, I think generalized handling of forms is just a hard problem - I have yet to see a library that handles every case, nor do I know how I'd go about writing one. There is the package wtforms, however, which I've found is more pleasant than django forms.
- znt 13y agoMaybe try these libraries next time: Crispy forms: http://django-crispy-forms.readthedocs.org/en/latest/ http://django-crispy-forms.readthedocs.org/en/latest/ Floppy forms:http://django-floppyforms.readthedocs.org/en/latest/ http://django-floppyforms.readthedocs.org/en/latest/