django-tables2

Django-tables2: How to use accessor to bring in foreign columns?

只愿长相守 提交于 2019-12-04 20:16:01
问题 I've tried reading the docs and previous answers to this question without much luck. I've got a bunch of student-course registrations and I'd like to see some of those selected registrations in conjunction with some of the attributes of the students. No luck so far...I'd request your advice! Here's the model: class Student(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) netID = models.CharField(max_length=8) class Registration(models

django-tables2 add button per row

半城伤御伤魂 提交于 2019-12-04 04:59:00
I'm rendering a queryset with django-tables 2 but since the table is rendered at once I can't manage the following: Firstly, I should mention that the number of rows of the table is different with each queryset so I don't know the exact number of them in advance. What I need, is to have one button per row that loads the retrieved object inside the fields of a form. I render the table with the default way: {% load render_table from django_tables2 %} {% render_table table %} When I try to iterate over the rows of the tables I get the error 'table is not iterable'. So how can I add one button per

Django-tables2: How to use accessor to bring in foreign columns?

牧云@^-^@ 提交于 2019-12-03 12:56:31
I've tried reading the docs and previous answers to this question without much luck. I've got a bunch of student-course registrations and I'd like to see some of those selected registrations in conjunction with some of the attributes of the students. No luck so far...I'd request your advice! Here's the model: class Student(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) netID = models.CharField(max_length=8) class Registration(models.Model): student = models.ForeignKey(Student) course = models.ForeignKey(Course) attendance_M = models

badly formed hexadecimal UUID error string for a UUID primary key

不问归期 提交于 2019-12-02 10:01:13
I'm trying to get my table to load, but am getting this error, most likely because my primary key is a uuid. Here is my url paths. path('results/', views.results, name='results'), path('results/<uuid:pk>/', views.genre_book, name='books_genre_table'), Here is my views.py If there is one observation, we load the price table. If not, then we load a table with service descriptions. The user can then pick the service they are most interested and click through to the price table for that service. This is not working. The first view "results" works, but the second view book_genre does not. def

select all rows in django_tables2

僤鯓⒐⒋嵵緔 提交于 2019-12-01 19:08:57
I have tried to select all rows in a table by clicking on the upper check box in a CheckBoxColumn with the following definition: selection = tables.CheckBoxColumn(accessor="pk", orderable=False) However the rows are not selected, is there anything else I need to do? I am using django 1.4.1 and django_tables2 0.13.0. Miguel de Val-Borro It is possible to select all checkboxes in a CheckBoxColumn by replacing the input attribute in the header cell: selection = tables.CheckBoxColumn(accessor="pk", attrs = { "th__input": {"onclick": "toggle(this)"}}, orderable=False) Then this JavaScript construct

select all rows in django_tables2

喜夏-厌秋 提交于 2019-12-01 17:38:32
问题 I have tried to select all rows in a table by clicking on the upper check box in a CheckBoxColumn with the following definition: selection = tables.CheckBoxColumn(accessor="pk", orderable=False) However the rows are not selected, is there anything else I need to do? I am using django 1.4.1 and django_tables2 0.13.0. 回答1: It is possible to select all checkboxes in a CheckBoxColumn by replacing the input attribute in the header cell: selection = tables.CheckBoxColumn(accessor="pk", attrs = {

Trouble trying to dynamically add methods to Python class (i.e. django-tables2 'Table')

不问归期 提交于 2019-12-01 17:29:10
So for a Django project, I would really like to be able to generate and display tables ( not based on querysets) dynamically without needing to know the contents or schema beforehand. It looks like the django-tables2 app provides nice functionality for rendering tables, but it requires that you either explicitly declare column names by declaring attributes on a custom-defined Table subclass or else provide a model for it infer the columns. I.e, to use a column named "name", you'd do: class NameTable(tables.Table): name = tables.Column() The Tables class does not provide a method for adding

Trouble trying to dynamically add methods to Python class (i.e. django-tables2 'Table')

风格不统一 提交于 2019-12-01 16:20:50
问题 So for a Django project, I would really like to be able to generate and display tables ( not based on querysets) dynamically without needing to know the contents or schema beforehand. It looks like the django-tables2 app provides nice functionality for rendering tables, but it requires that you either explicitly declare column names by declaring attributes on a custom-defined Table subclass or else provide a model for it infer the columns. I.e, to use a column named "name", you'd do: class

Non-queryset data ordering in django-tables2

拜拜、爱过 提交于 2019-12-01 15:35:53
The docs say: Where the table is backed by a model, the database will handle the ordering. Where this is not the case, the Python cmp function is used and the following mechanism is used as a fallback when comparing across different types: ... But is this possible in a table that is backed by a model, on a custom column? e.g. class MyModel(models.Model): x = models.IntegerField() y = models.IntegerField() def z(self): return x+y class MyTable(tables.Table): z = tables.Column() class Meta: model = MyModel When I try something like this, the column displays OK, but when I click on the column

How to get information from Django_tables2 row?

泪湿孤枕 提交于 2019-11-30 21:29:56
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. You need to choose a suitable value for the CheckBoxColumn . Generally if you're displaying a queryset, you'll use the pk of each object for the CheckBoxColumn .