Split form into tabs in Django - django

I'm developing a Django app which has database driven form fields. I've followed this guide which seems to work so far.
I'm using Twitter Bootstrap and would like to split my fields into tabs. What would be the Django way to do this? Should I append the group label to the id of the form fields and somehow do the magic in the template? Should I use multiple forms in the same view (seems complicated)?
The end result HTML wise is to enclose the input fields in the correct div elements with the group's id like so.

I recently required the very same thing.
After some research, I used django-crispy-forms, which worked quite well. A more detailed instructions about the tabs (and the need of .js file for animation) can be found here, in the 'tabs' section.

Related

Django Form so many fields

I have a Django page using bootstrap and crispy forms that present a form. but the form is growing so much now that I probably have around 50 fields :( which are all within 1 massive HTML page. I'm pretty sure this is the wrong way to do it.
Is it possible to split the forms into say 5 pages, but still have a submit button to post all of the fields to the database?
For now, what I have done is to create tabs for each section of the giant form so it's easy than scrolling.
I'm thinking it's probably better to create different views for each section and then link the data somehow back using an IndexKey or something?
But i have no idea how i would configure the button to capture all the fields.
I know this is a rubbish question, but I don't really know what to search for?
Cheers
You can try to divide the form in bootstrap tabs like
Personal information --> form fields
Additional information --> form fields
Why don't you break the data input down into as many questions as you think is appropriate for each page? If you have 50 inputs, you could do 10 over 5 pages.
After submitting Page 1, return the POST data to Page 2 and store the data in hidden input fields. Repeat the process until Page 5 when you can POST all 50 to the server and insert the data into your Database.

What is the right way of containing data in django?

I'm rebuilding school project from html page to django app. In old project I had some articles and two tests.
For articles I created django model with text field and pasted in it article's content with HTML due to it have some decorations as a <"code> <"/code> tags.
How should I contain tests if first is build with HTML forms and second with <"canvas>? Should I use text field again? Data is too complex. For the first test it goes as a forms with individual texts and inputs and checked by javascript. For second it is initializing js functions.
How they are look like:
First test with forms
Second test with canvas
Where can I read about it more?
P.S. Sorry for bad english

Django form with autocomplete functionality

I am working on a django project with complex forms. In one of my form fields I need following functionality...... Its the text field. As the user starts typing the value the suggestions from existing database should appear in dropdown. Can anyone help me out with this ? Just similar to autocomplete but able to add new values.
This is going to be something in the JQuery/AJAX side of things, not Django. I would read up on the autocomplete functions of JQuery and use AJAX to call your DJango code and receive a populated list, which then displays to the user.
JQuery Autocomplete - Custom Data
If you don't want to deal with JavaScript, you can use a django application called django-autocomplete-light.
You can learn more about it (and get it) here: https://github.com/yourlabs/django-autocomplete-light

How customize fields in the Django admin interface

I have a model in my Django project with a member which is a char field. Basically data in this field will be entered as comma-separated values.
Without a long-winded explanation of what the overall goal of this is, basically rather than having the admin interface use a simple text field, I'd rather have have some custom HTML for the form so I can just use checkboxes and assemble the values of the checked boxes into a CSV string myself once the form is submitted.
Most of the django customization I was able to find on Google didn't answer my particular problem.
If I understand your question correctly I think you want to search for writing custom widgets. Perhaps start here: http://docs.djangoproject.com/en/dev/topics/forms/

What is the best UI for selecting tags from a list of existing tags?

I am using django-tagging. My model simply contains a field with a comma separated list of tags. I would like the user to be able to select tags from a list of already existing tags and also allow the user to add tags. Still resulting a comma-separated list of tags. How would I do that?
A pull down list doesn't work. I was thinking about simply listing all tags beneath the tag field and when a user clicks on an existing tag this is added to the tag field with a bit of javascript.
Other ideas are very welcome.
If you can use jquery there are several plugins to handle this and save you the JS coding:
Tag Suggest which can handle comma delimited tag lists and Autocomplete which also has the advantage of being used by Jannis Leidel's excellent autocomplete form widget for ForeignKey model fields
Having a separate complete list is a good start. I would also suggest an autocomplete implementation while the user is typing a tag name into the box. This helps eliminate the problem of having Batman and Bat-man and Bat Man as three separate tags.
I think your proposal of showing all tags and allowing the user to select them individually is a sound approach. Delicious.com uses this exact interface and it works wonderfully.
How about implementing it the same way Stack Overflow does for the ignored and interesting tags on the front page? Wait for the user to start typing, and as they do, fire off AJAX requests to the server and start returning the five most likely results, which you can then display in a hovering white box below the text box.