Экспорт только выбранных строк в Django-Tables2 - PullRequest
0 голосов
/ 24 апреля 2019

Я использую Django tables2.У меня есть n количество строк на странице, и я хочу export only the rows which the user selects.Но я не могу найти способ заставить это работать.Официальная документация не помогает.

Когда я выбираю строки, которые хочу экспортировать, а затем нажимаю кнопку экспорта.The entire table is exported.

tables.py

class TrackerTable(tables.Table):
    export_formats = ['csv', 'xls', 'xlsx', 'json']
    id = tables.Column()
    id = tables.LinkColumn('posts:tracker_view',args=[A('pk')], empty_values=())
    editable = tables.LinkColumn('posts:modify',args=[A('pk')] , empty_values=(), verbose_name='')
    selection = tables.CheckBoxColumn(accessor=A('pk')t ,empty_values=(), footer='', attrs = { "th__input":{"onclick": "toggle(this)"}}, orderable=False)
    def render_editable(self):
        #return 'Edit'
        return mark_safe('<center><p style="color:blue;">&#9997;</p></center>')



    class Meta:
        model = models.Post
        template_name = 'django_tables2/semantic.html'
        sequence = ('selection','editable','id','...')
        attrs = {'tbody': {'id': 'myTable'}}

views.py

    table = TrackerTable(Post.objects.all(), order_by="-id")
    RequestConfig(request).configure(table)
    export_format = request.GET.get('_export', None)
    if TableExport.is_valid_format(export_format):
        exporter = TableExport(export_format, table, exclude_columns=('editable','selection'))
        return exporter.response('table.{}'.format(export_format))

    return render(request, 'posts/tracker_list.html', {'table': table})```
...