Karan
Karan

Reputation: 269

Customize column for django-tables as drop down list

I have a table in which I compare the two versions of a selected Data. This data actually has more than one version stored, so in my table I have column as:

    class ver_compare(tables.Table):
       new_db = tables.CheckBoxColumn()
       data = tables.Column()
       current_rev = tables.Column()
       next_rev = tables.Column()*

Now the last field I want as a each cell to have a drop down list of version to select from, something similar to choicefield. Is there any approach to go along??

Thanks in advance!!

Upvotes: 2

Views: 3699

Answers (1)

KCiebiera
KCiebiera

Reputation: 820

You can use TemplateColumn. Here you have the simplest mockup I can think of . Of course you need to change template to something more useful.

countries = [
    {'name': 'Australia', 'population': 21, 'tz': 'UTC +10', 'visits': 1},
    {'name': 'Germany', 'population': 81, 'tz': 'UTC +1', 'visits': 2},
    {'name': 'Mexico', 'population': 107, 'tz': 'UTC -6', 'visits': 0},
]

template = """
<select>
<option{% if record.visits = 0%} selected {% endif %}>0
<option{% if record.visits = 1%} selected {% endif %}>1
<option{% if record.visits = 2%} selected {% endif %}>2
</select>
"""

class CountryTable(tables.Table):
    name = tables.Column()
    population = tables.Column()
    tz = tables.Column(verbose_name='time zone')
    visits = tables.TemplateColumn(template)

Upvotes: 5

Related Questions