django-tables2

django tables2 create extra column with links

我是研究僧i 提交于 2019-11-30 15:45:54
问题 I am trying to add a extra column to one of my tables, that adds url to another page. My Table: class ItemTable(tables.Table): edit = tables.LinkColumn('item_edit', args=[A('pk')]) class Meta: model = Item fields = ('name', 'slot', 'klass', 'rarity', 'price') my urls: url(r'^admin/item/edit/(?P<item_id>\d+)/$', views.item_edit, name='item_edit') Now with this, i get my table, but the last column (edit) only has dashes + the page crashes when i click the title. i have been looking at http:/

django tables2 create extra column with links

倾然丶 夕夏残阳落幕 提交于 2019-11-30 15:12:00
I am trying to add a extra column to one of my tables, that adds url to another page. My Table: class ItemTable(tables.Table): edit = tables.LinkColumn('item_edit', args=[A('pk')]) class Meta: model = Item fields = ('name', 'slot', 'klass', 'rarity', 'price') my urls: url(r'^admin/item/edit/(?P<item_id>\d+)/$', views.item_edit, name='item_edit') Now with this, i get my table, but the last column (edit) only has dashes + the page crashes when i click the title. i have been looking at http://django-tables2.readthedocs.org/en/latest/#django_tables2.columns.LinkColumn and im not sure where i go

Custom columns in django_tables2

独自空忆成欢 提交于 2019-11-30 14:01:51
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 = MyModel # views.py table = MyTable(MyModel.objects.all()) RequestConfig(request).configure(table) return

How to get information from Django_tables2 row?

风流意气都作罢 提交于 2019-11-30 05:12:39
问题 I have declared a table and want to fetch the row's value which is checked using checkboxfield. Any help, how can i write this event in my views so that everytime I select a row and hit submit button, it returns the row's values.Code goes like this: class mytables(tables.Table): new_database = tables.CheckBoxColumn() student =tables.Column(accessor='Student') Class = tables.Column(accessor='class') And in my templates a submit button. 回答1: You need to choose a suitable value for the

django-tables2 linkcolumn multiple items in the same cell

与世无争的帅哥 提交于 2019-11-29 05:06:49
I'd like to add multiple 'items' to the same cell using tables.LinkColumn . Something like this: column_name = tables.LinkColumn('some_url_edit', args=[A('pk')], attrs={'class':'tbl_icon edit'}) column_name += tables.LinkColumn('some_url_del', args=[A('pk')], attrs={'class':'tbl_icon delete'}) column_name += ... Is this even possible? or should I create my own table view, without django-tables . Thanks! You have two options here, either use a TemplateColumn , or write a render_FOO method. Here is an example using the TemplateColumn (as you can see the record is added to the context that is

How do I filter tables with Django generic views?

爷,独闯天下 提交于 2019-11-28 20:57:39
I am trying to create a table view with pagination, sorting, and filtering, using the most common/standard/recommended approach for Django 1.6. This seems to be Generic Class-Based Views and django-tables2. I've found at least two different examples of how to add filtering, one with django-filters and crispy-forms and the other with django_filters , but neither includes a complete working example. When I follow either approach, I get stuck filling in the missing material. Using the crispy approach from Nicolas Kuttler, I have: models.py from django.db import models class Author(models.Model):

Django: django-tables2 pagination and filtering

丶灬走出姿态 提交于 2019-11-28 08:13:53
问题 I have a working table generated by django-tables2: my_filter = TestFilter(request.POST) table = TestTable(TestObj.objects.all(), order_by="-my_date") RequestConfig(request, paginate={"per_page": 10}).configure(table) return render(request, 'test_app/index.html', {'table': table, 'my_filter': my_filter}) The above code returns a table with hundreds of objects that are neatly paginated with 10 items per page. When I click "Next" at the bottom of the table, pagination works well and I can

Django Tables - Column Filtering

我与影子孤独终老i 提交于 2019-11-27 22:58:44
I started using django-tables2 (which I can highly recommend from the first impression) and I m asking myself how to implement column filtering. I do not find the appropriate documentation for it, but I m sure it is somewhere out there. A little late answer but anyway ... I also couldn't find any appropriate documentation for column filtering. There are many methods to do it: A. By hand : I add a form containing the fields I'd like to filter with and then I do something like this in my view: data = models.MyClass.all() form = forms.MyFilterForm(request.GET) if request.GET.get('field1'): data =

django-tables2 linkcolumn multiple items in the same cell

爱⌒轻易说出口 提交于 2019-11-27 22:37:39
问题 I'd like to add multiple 'items' to the same cell using tables.LinkColumn . Something like this: column_name = tables.LinkColumn('some_url_edit', args=[A('pk')], attrs={'class':'tbl_icon edit'}) column_name += tables.LinkColumn('some_url_del', args=[A('pk')], attrs={'class':'tbl_icon delete'}) column_name += ... Is this even possible? or should I create my own table view, without django-tables . Thanks! 回答1: You have two options here, either use a TemplateColumn, or write a render_FOO method.

How do I filter tables with Django generic views?

浪子不回头ぞ 提交于 2019-11-27 13:22:30
问题 I am trying to create a table view with pagination, sorting, and filtering, using the most common/standard/recommended approach for Django 1.6. This seems to be Generic Class-Based Views and django-tables2. I've found at least two different examples of how to add filtering, one with django-filters and crispy-forms and the other with django_filters, but neither includes a complete working example. When I follow either approach, I get stuck filling in the missing material. Using the crispy