django-tables2

cell color Django-Tables2

[亡魂溺海] 提交于 2019-12-08 12:02:49
问题 Question: Where do I edit my django code to change the background color of individual cells based on business logic? In my views.py I have logic that captures the max value of column 'pts': def show_teams(request): reg = Teamoffense.objects.filter(~Q(rk='RK')) pts = Teamoffense.objects.filter(~Q(pts='PTS')).values('pts') seq = [item['pts'] for item in pts] maxseq = max(seq) table = SimpleTable(reg) table_to_report = RequestConfig(request).configure(table) if table_to_report: return create

Using “record” in attributes Django Tables 2

余生长醉 提交于 2019-12-08 06:58:50
问题 I'm moving my tables to django-tables2. By now is almost everything working ok, but now I have a problem. In my current version i use checkboxes to select items <td><input type="checkbox" class="checkbox_delete" name="event" id="event.id" value="{{ event.id }}" /> this way in the view i can recover the event.id using request.POST.getlist('event') Now I'm trying to add the "value" attribute to a CheckBoxColumn select = tables.CheckBoxColumn(attrs={'td__input': {'class': 'checkbox_delete',

How to put submit buttons for every record in django tables 2?

六月ゝ 毕业季﹏ 提交于 2019-12-08 05:02:43
问题 I have a django_tables2 table inside a form, this is necessary because there's a delete selected button on top. In every row, I need a submit button with some action like 'accept', 'deny', etc. But I don't know how to recognize the row of which the button was pressed. How can I accomplish this? 回答1: I have found this way to add a button to each row with an id that refers to the row you select : in app/tables.py import django_tables2 as tables from app.models import MyModel from django.utils

django-tables2 linkColumn accessor

天大地大妈咪最大 提交于 2019-12-08 04:26:09
问题 I have been using django-tables2 which I like, but i run into some problems I am trying to make a table in which cells link out to a different table, or an outside link the example in the documentation is : models.py class Person(models.Model): name = models.CharField(max_length=200) urls.py urlpatterns = patterns('', url('people/(\d+)/', views.people_detail, name='people_detail') ) tables.py from django_tables.utils import A # alias for Accessor class PeopleTable(tables.Table): name = tables

Django Tables2 Display Multiple Tables

拟墨画扇 提交于 2019-12-08 03:26:16
问题 I've got user records that have related(ish) course and enrollment records. I want to click on a user and see raw data from the user table, course table, and enrollment table in the same page. The process breaks down when I attempt to render the tables. views.py: def explore_related(request, client_id, user_id): client = get_object_or_404(Client, pk=client_id) users = Users.objects.filter(pk=user_id) enrollments = Enrollments.objects.filter(client_id=client_id).filter(userID__in=users.values

How to put submit buttons for every record in django tables 2?

风流意气都作罢 提交于 2019-12-06 17:33:27
I have a django_tables2 table inside a form, this is necessary because there's a delete selected button on top. In every row, I need a submit button with some action like 'accept', 'deny', etc. But I don't know how to recognize the row of which the button was pressed. How can I accomplish this? GGette1011 I have found this way to add a button to each row with an id that refers to the row you select : in app/tables.py import django_tables2 as tables from app.models import MyModel from django.utils.safestring import mark_safe from django.utils.html import escape class MyColumn(tables.Column):

How to change color of Django-tables row?

ぃ、小莉子 提交于 2019-12-06 11:07:18
问题 is it possible to change a color of row based on current object's value? In my case, I have a table created from model Job . The Job has attribute delivery . If job.delivery is for example 'delivered', I want to change the color of the row to red. The only thing comes to my mind is to use JQuery but I'm not sure if it is not an overkill. class MyOrdersTable(tables.Table): edit_entries = tables.TemplateColumn( '{% if not record.translator %}<a href="/jobs/update/{{record.id}}">Edit Order</a>{%

The linkcolumn about django-tables2

 ̄綄美尐妖づ 提交于 2019-12-05 23:12:16
问题 I use django-tables2 to show some data in page,and now I want to make the cell link to some url,but the link url such as : url(r'^(?P\w+)/(?P\d+)/$', 'pool.views.pooldatestock', name="pool_date_stock"), and I read the documents of django-tables2,but I can't find some excample about this problem. the tables show in the page's url just like:http://127.0.0.1:8000/pool/20111222/ I try to write this in my tables.py : class PoolTable(tables.Table): number = tables.LinkColumn('pool.views

django-tables2 specify different properties for different rows

眉间皱痕 提交于 2019-12-05 04:30:15
I would like to create a table with django-tables2 such that different rows have different properties. By default I get either <tr class="odd"> or <tr class="even"> How can I specify my own class for some of the rows? Similarly, if I have a CheckBoxColumn and I specify some data for this column, it goes into the value : <input type="checkbox" name="col" value="123"/> This is great for figuring out which checkbox was checked. However, how can I set some checkboxes as checked when the table is created? My scenario: the user picks some rows from a large table. For example, the table has orange 1

Django-tables2 - dynamically adding columns to table - not adding attrs to table tag in html

强颜欢笑 提交于 2019-12-05 03:55:55
In my Django project I need to have tables which columns are dynamic and depend on what is in the database. So I found a solution in here and it works but with a little problem. Here's the class with a table I'm extending dynamically: class ClientsTable(tables.Table): class Meta: model = Client attrs = {"class": "paleblue", "orderable":"True", "width":"100%"} fields = ('name',) def __init__(self, *args, **kwargs): super(ClientsTable, self).__init__(*args, **kwargs) self.counter = itertools.count() def render_row_number(self): return '%d' % next(self.counter) def render_id(self, value): return