0

I'm trying to populate a django table with autocomplete light so that the user can fill in data in the table, which would then be saved (the whole table is in a form tag). I have the table working to display the existing data and I have the autocomplete working in model forms (well, a team member got that part working), but I don't know how to combine the two. The docs are a bit of a mystery to me, but maybe if someone could at least point me in the right direction I'd greatly appreciate it.

I've tried a few random things to combine them, but honestly they were such stabs in the dark that I don't think they're even worth mentioning.

tables.py

class ModifyTable(tables.Table):
    name            = tables.LinkColumn('app-view', args=[A('pk')], verbose_name='Name')
    primary_contact    = tables.Column()
    secondary_contact  = tables.Column()

autocomplete

autocomplete_light.register(Person,
    search_fields=['first_name', 'last_name', 'username'],
    split_words=True,
    autocomplete_js_attributes={'placeholder': 'Find a user',},
)
thumbtackthief
  • 6,093
  • 10
  • 41
  • 87

1 Answers1

-1

Django-tables2 provides an API to generate data tables in HTML.

Django-autocomplete-light provides a widget that enables autocompletion inputs.

This widget must be used in a Form. The django Form class will combine your the HTML <form> with models used by django-tables2.

However, a Form must be used by a Formsets to be repeated for every row in the table. Note that you could consider modelformset_factory to generate such a formset.

Use a formset and your work is done here ;)

jpic
  • 32,891
  • 5
  • 112
  • 113
  • The places were the user has to enter data involve a fk lookup of 10,000 items. I want the user to be able to use auto-complete there. – thumbtackthief Nov 17 '13 at 22:58
  • Oh, you -1'd the one person who was trying to help you, great move :D BTW, I'm the author of django-autocomplete-light and I garantee that autocomplete widgets work in formsets and with lookups of 100 000 or even 1 000 000 items :) Let me know when you improve your question. – jpic Nov 20 '13 at 16:11
  • I wasn't trying to insult you. I am new here and thought that's what I supposed to do. I thought my question was clear--if I'm wrong, please let me know how I can improve it and I happily will. – thumbtackthief Nov 20 '13 at 16:18
  • I'm apparently unable to remove the -1 unless you edit your answer somehow. But I tried. – thumbtackthief Nov 20 '13 at 16:19
  • To be fair, though, your answer to "How can I use django-tables2 with auto-complete?" didn't involve either django-tables2 or auto-complete. – thumbtackthief Nov 20 '13 at 16:20
  • Well, you have a table2 table, you have an autcomplete class. But where is your formset ? FEAR NOT: if you don't know what a formset is, my answer has a link to the official documentation on formsets ;) – jpic Nov 24 '13 at 21:19
  • Could you post your formset please ? Thanks ! – jpic Dec 01 '13 at 11:29
  • Hi, are you still "stabbing in the dark" or did you try to use formsets ? Thanks for your feedback ! – jpic Dec 11 '13 at 10:38
  • The issue's been temporarily tabled (heh) but I will return to it and update the question soon! – thumbtackthief Dec 11 '13 at 14:31