Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Sexiest Solution</h1> <p>You could use one of the jquery autocommplete tools described here: <a href="https://stackoverflow.com/questions/1191807/facebook-style-jquery-autocomplete-plugin">Facebook style JQuery autocomplete plugin</a></p> <p>Then in the form:</p> <pre><code>class ToolBoxEditForm (ModelForm): tools = forms.CharField(widget=forms.Textarea, required=False) def clean_tools(self): tool_data = self.cleaned_data.get('tools',None) tools = [] #here, a comma is used a delim, so it's not allowed in the tool name. for td in tool_data.split(','): t, _ = Tool.objects.get_or_create(name=td) tools.append(t) return tools class Meta: model = ToolBox exclude = ('user', 'popularity',) </code></pre> <p>You'd have to figure out how to modify the JavaScript so that new items could be entered (i.e. not just ones already in the database).</p> <h1>Alternative Solution</h1> <p>This is sort of what the <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets" rel="nofollow noreferrer">inline formsets</a> were created for, so <a href="https://stackoverflow.com/questions/3620611/how-to-change-multiple-select-field-to-multiple-input-fields-for-a-many-to-many-c/3626725#3626725">Narendra's solution</a> will work.</p> <p>Something like:</p> <pre><code>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() # Do something. else: formset = ToolInlineFormSet(instance=toolbox) return render_to_response("manage_toolbox.html", { "formset": formset, }) </code></pre> <p>Not that this form is only for editing the items within the toolbox. If you want the user to be able to edit other aspects of the Toolbox -- say, its name or description -- you would create a separate form and output both of them inside the same <code>&lt;form&gt;&lt;/form&gt;</code> tags.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload