django-tables2

Django-tables2 send parameters to custom table template

扶醉桌前 提交于 2021-01-29 05:32:51
问题 I'm trying to use a custom table template to embed the django-filter fields on my table. So I copied the django-tables2 bootstrap.html template in a new file custom_table.html . Then I added it the following code in the thead section: {% if filter %} <tr> {% for filter_field in filter.form.fields %} <td> {{ filter_field }} </td> {% endfor %} <td> <button class="login100-form-btn" type="submit">Filter</button> </td> </tr> {% endif %} So the problem is : how can I send the filter to the table

Error Using django-tables2 - Expected table or queryset, not 'str'

纵然是瞬间 提交于 2020-07-17 06:28:21
问题 I am trying to create some tables for my application using django-tables2 and running into some difficulties. I am using Python 2.7, and Django 1.7. I am following the tutorial, and I ran into problems. I reach the point where I need to create a Table class for customization. However, whenever I do so, I get the following error: Expected table or queryset, not 'str'. After doing some research it looks like I am using an older version of django-tables2. However, I just installed it yesterday

How to export .csv with Django-Tables2?

大憨熊 提交于 2020-06-01 06:22:10
问题 I'm trying to export a table in .csv with Django-Tables2, I've done the following so far. tables.py class ClientTable(ColumnShiftTable): class Meta: model = Client sequence = ('id', 'nome_razao_social', 'cpf', 'cnpj', 'sit_fiscal') template_name = 'django_tables2/bootstrap.html' views.py class ClientsView(ExportMixin, CustomListView): template_name = 'relatorios/clients/geral.html' model = Client table_class = ClientTable context_object_name = 'all_clients' permission_codename = 'view_clients

Display relevant records from many to many in django-tables2

偶尔善良 提交于 2020-03-24 10:01:10
问题 OK, so I have an Item class that has a many-to-many attribute to User through a 'Roles' class. I am trying to create a django-table for the Items such that out of any of the roles attached to the item, if the current User is attached to that role, the name of the role displays. I hope that makes some sort of sense. Here's what I have so far, which I didn't really expect to work because I don't see how the Table class can know about the request/user. I'm stuck. models.py class Item(models

How to change the column header of a django-tables2 table in the view.py?

霸气de小男生 提交于 2020-01-25 03:11:26
问题 I'm using django-tables2 in my Django project and I would like to change dynamically the header of some columns according to a database query, which is done in view.py. I know that in tables.py one can change the "verbose_name" attribute of each and every column but I would like to assign a template variable "{{ headerxy }}" for example so that it changes dynamically. Or is there a way to change the "verbose_name" attribute in the view.py ? Something like: table.columns['column1'].header =

django tables2 checkbox

荒凉一梦 提交于 2020-01-24 14:27:06
问题 I'm new to programming so this may be a trivial question... In django-tables2, I'd like to be able to display the column header name when using CheckBoxColumn. Right now, all the checkboxes are displaying for each row, including in the header. I don't mind having a checkbox in the header (I figure that would be a great way to do a "select all" in the long run), but I need the column name to display. Does anyone have a solution for this? 回答1: Create your own custom checkbox column class that

django tables2 checkbox

情到浓时终转凉″ 提交于 2020-01-24 14:27:04
问题 I'm new to programming so this may be a trivial question... In django-tables2, I'd like to be able to display the column header name when using CheckBoxColumn. Right now, all the checkboxes are displaying for each row, including in the header. I don't mind having a checkbox in the header (I figure that would be a great way to do a "select all" in the long run), but I need the column name to display. Does anyone have a solution for this? 回答1: Create your own custom checkbox column class that

Django - Override data content of a django-tables2 LinkColumn

风流意气都作罢 提交于 2020-01-14 22:42:52
问题 I use django-tables2 LinkColumn to create a column that call a function that allow the export of the object in the table. forms.py: class FilesTable(tables.Table): id = tables.LinkColumn('downloadFile', args=[A('pk')], verbose_name='Export') I would like the content of this column to be the href to downloadFile function with: Export as the text, not the id. 回答1: Something like that should be working ( warning I don't have Python here so it's not tested but you'll get the idea): class

Custom columns in django_tables2

南笙酒味 提交于 2020-01-10 19:32:26
问题 I've had a search around for this but haven't had much luck so looking for a bit of help. I'm trying to add some extra columns to a table defined by a model, using function definitions in the model. Here's what my code looks like now: # models.py class MyModel(models.Model): my_field = models.TextField() def my_function(self): # Return some calculated value based on the entry return my_value # tables.py class MyTable(tables.Table): my_extra_column = tables.Column(....) class Meta: model =

Custom columns in django_tables2

夙愿已清 提交于 2020-01-10 19:32:06
问题 I've had a search around for this but haven't had much luck so looking for a bit of help. I'm trying to add some extra columns to a table defined by a model, using function definitions in the model. Here's what my code looks like now: # models.py class MyModel(models.Model): my_field = models.TextField() def my_function(self): # Return some calculated value based on the entry return my_value # tables.py class MyTable(tables.Table): my_extra_column = tables.Column(....) class Meta: model =