The sexiest decision
You can use one of the jquery autocomplete tools described here: JQuery autocomplete plugin for Facebook
Then in the form:
class ToolBoxEditForm (ModelForm): tools = forms.CharField(widget=forms.Textarea, required=False) def clean_tools(self): tool_data = self.cleaned_data.get('tools',None) tools = []
You will need to figure out how to change JavaScript so that you can introduce new elements (i.e. not just the ones already in the database).
Alternative solution
This is what was created by the built-in form sets , so the Narendra solution will work.
Sort of:
from django.forms.models import inlineformset_factory def manage_toolbox(request, toolbox_id): toolbox = Toolbox.objects.get(pk=toolbox_id) ToolInlineFormSet = inlineformset_factory(Toolbox, Tool) if request.method == "POST": formset = ToolInlineFormSet(request.POST, request.FILES, instance=toolbox) if formset.is_valid(): formset.save()
Not that this form was just for editing items in a toolbar. If you want the user to be able to edit other aspects of the toolbar - say, its name or description, you would create a separate form and display both of them in <form></form> tags.
source share