Sunday, July 30, 2017

Re: Django form needs pagination and saved data - how????



On Jul 30, 2017 4:50 PM, "Jim Illback" <subaru_87@hotmail.com> wrote:
Thanks for your reply, James. Appreciate it. BTW, if you check my template, the button is within the form tags, but you probably are right on the JS - I don't know JS much at all so just copied other people's code.

I thought that's how you're supposed to program in JS? Been doing it that way for years. ;-)


I may be mistaken, but I think the wizard link below requires a "static" or semi-static forms flow path (form1, form2, …, formlast). Generally, when you do pagination, there is no preset number of pages - it depends upon the data being requested or available. So, I think that option would not work. But, if I'm wrong, I'd love to know. Thanks.

By default, yes, it is expecting a known number of steps for more simple processes. However, it has all of the hooks necessary to create a fully dynamic flow. I did a dynamic flow back when this package was still in Django core, but I doubt the process has changed much.


And, as for using Java just so you can use Django, doesn't that raise the obvious question - so why use Django? 

I'm not sure what you're referring to here. I don't think that I mentioned Java specifically, nor would I have reason to.

Perhaps a mistaken interpretation of my reference to an SPA? This is what I meant:



To try to illustrate that my issue is a common business issue, here's a scenario that is exactly the same situation and one used by almost everyone:

A new car purchase site needs the user to pick the car and model. Then, that data stays static throughout the transaction. However, the user might want different options (tires, engines, transmission types, etc.). And, those options are always too many for one page, so they must be done using pagination. When all the options are reviewed - or maybe just one page of options or two or… - then the final idea is to show the user the car's price, have all the selections chosen listed out for the user to review, and ask for further actions like "do you want to purchase this car?". 

Are these types of business scenarios just not in Django's wheelhouse? 


The level of dynamic content generation required for all of those steps will likely be complex, possibly even complicated, for any generic framework to handle. The Django formtools can handle the scenario you've listed, but your code organization and naming standard will need to be strongly enforced to keep the various steps separate.

The workflow you've mentioned isn't necessarily complicated at a high level, the step decisions are rather binary. Either a person wants to select different tires, or doesn't and accepts the default selection. The code in formtools for step selection is usually that simple "if they wanted different tires in a previous step, now show them this form for tires", almost a one-liner (for each step).

Honestly, the biggest issue will be displaying the multiple pages of options, which is somewhat a separate issue. 

There are several strategies. You can display multiple form pages across multiple requests, keeping the results of each along the way, which complicates your back end code. Before the influx of JS and HTML5, this was rather common. 

The newer approach is to use JS to pull all of the possible options, and handle the UI and pagination within JS, perhaps in a pop up modal window. The data is retrieved via an API call, and once a selection is made by the user, either a form is executed containing all of the possible options that the user selected. 

Datatables.js might be a good option for this, as it can also handle the dynamic pagination of options surprisingly well, and plays excellent with Bootstrap. Heck, you can probably use DT with either strategy. It would definitely ease the logic for the server based form wizard, and likely save you a ton of JS scripting for an SPA-like display.

If it were me, I'd investigate Datatables.js with the Bootstrap integration and pagination. It's relatively easy to implement (I, like yourself, am averse to JS), and provides killer functionality with minimal custom JS (mostly single minimal function calls to control ordering of table columns). Once you have that working, try integrating the table with a form combined with pagination, I think that will be the silver bullet you're looking for.


-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV46BEkatAmD9kGX5ugdfmZn7GQsfnjbdte5cey4YxC4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment