0

我正在尝试使用自动完成灯填充 django 表,以便用户可以在表中填写数据,然后将其保存(整个表在表单标签中)。我有表格来显示现有数据,并且我有自动完成以模型形式工作(嗯,一个团队成员让这部分工作),但我不知道如何将两者结合起来。这些文档对我来说有点神秘,但如果有人至少能指出我正确的方向,我将不胜感激。

我尝试了一些随机的东西来组合它们,但老实说,它们是在黑暗中刺痛的,我认为它们甚至不值得一提。

表格.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_light.register(Person,
    search_fields=['first_name', 'last_name', 'username'],
    split_words=True,
    autocomplete_js_attributes={'placeholder': 'Find a user',},
)
4

1 回答 1

-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 ;)

于 2013-11-17T11:35:40.580 回答