5 ms·
The idea in Django is that you really want to break up your project into several apps, with each app having just a handful of models and views. Aside from depen
by Daishiman 13y ago
The idea in Django is that you really want to break up your project into several apps, with each app having just a handful of models and views. Aside from depending on some conventions such as a models and views file for each app, apps can live anywhere, so you can separate them through subdirectories if that works for you.
The forms API is, granted, not super easy to work with initially, but its abstractions are really powerful and bending them to your will is trivial, because everything is overridable.
- cujo 13y agoWhen 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/