This file is indexed.

/usr/share/doc/python-django-tables2-doc/html/index.html is in python-django-tables2-doc 0.13.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>django-tables2 - An app for creating HTML tables &mdash; django-tables2 0.13.0 documentation</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.13.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="django-tables2 0.13.0 documentation" href="#" />
    <link rel="next" title="Internal APIs" href="internal.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="internal.html" title="Internal APIs"
             accesskey="N">next</a> |</li>
        <li><a href="#">django-tables2 0.13.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="django-tables2-an-app-for-creating-html-tables">
<h1>django-tables2 - An app for creating HTML tables<a class="headerlink" href="#django-tables2-an-app-for-creating-html-tables" title="Permalink to this headline"></a></h1>
<p>django-tables2 turns data into HTML tables. Features:</p>
<ul class="simple">
<li>Pagination</li>
<li>Ordering</li>
<li>Extendable</li>
<li>Class based view</li>
<li>Supports for queryset and list data</li>
<li>Themes</li>
</ul>
<p>Report bugs at <a class="reference external" href="http://github.com/bradleyayers/django-tables2/issues">http://github.com/bradleyayers/django-tables2/issues</a></p>
<div class="toctree-wrapper compound">
</div>
<div class="section" id="tutorial">
<h2>Tutorial<a class="headerlink" href="#tutorial" title="Permalink to this headline"></a></h2>
<ol class="arabic simple">
<li><tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">django-tables2</span></tt></li>
<li>Add <tt class="docutils literal"><span class="pre">'django_tables2'</span></tt> to <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt></li>
</ol>
<p>We&#8217;re going to run through creating a tutorial app. Let&#8217;s start with a simple model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># tutorial/models.py</span>
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s">&quot;full name&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Add some data so you have something to display in the table. Now write a view
to pass a <tt class="docutils literal"><span class="pre">Person</span></tt> queryset into a template:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># tutorial/views.py</span>
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>

<span class="k">def</span> <span class="nf">people</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s">&quot;people.html&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s">&quot;people&quot;</span><span class="p">:</span> <span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()})</span>
</pre></div>
</div>
<p>Finally, implement the template:</p>
<div class="highlight-django"><div class="highlight"><pre><span class="c">{# tutorial/templates/people.html #}</span><span class="x"></span>
<span class="cp">{%</span> <span class="k">load</span> <span class="nv">render_table</span> <span class="nv">from</span> <span class="nv">django_tables2</span> <span class="cp">%}</span><span class="x"></span>
<span class="x">&lt;!doctype html&gt;</span>
<span class="x">&lt;html&gt;</span>
<span class="x">    &lt;head&gt;</span>
<span class="x">        &lt;link rel=&quot;stylesheet&quot; href=&quot;</span><span class="cp">{{</span> <span class="nv">STATIC_URL</span> <span class="cp">}}</span><span class="x">django_tables2/themes/paleblue/css/screen.css&quot; /&gt;</span>
<span class="x">    &lt;/head&gt;</span>
<span class="x">    &lt;body&gt;</span>
<span class="x">        </span><span class="cp">{%</span> <span class="k">render_table</span> <span class="nv">people</span> <span class="cp">%}</span><span class="x"></span>
<span class="x">    &lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span>
</pre></div>
</div>
<p>Hook the view up in your URLs, and load the page, you should see:</p>
<div class="figure align-center">
<img alt="An example table rendered using django-tables2" src="_images/tutorial.png" />
</div>
<p>While simple, passing a queryset directly to <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">render_table</span> <span class="pre">%}</span></tt> doesn&#8217;t
allow for any customisation. For that, you must define a <a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a> class.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># tutorial/tables.py</span>
<span class="kn">import</span> <span class="nn">django_tables2</span> <span class="kn">as</span> <span class="nn">tables</span>
<span class="kn">from</span> <span class="nn">tutorial.models</span> <span class="kn">import</span> <span class="n">Person</span>

<span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">Person</span>
        <span class="c"># add class=&quot;paleblue&quot; to &lt;table&gt; tag</span>
        <span class="n">attrs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;class&quot;</span><span class="p">:</span> <span class="s">&quot;paleblue&quot;</span><span class="p">}</span>
</pre></div>
</div>
<p>You&#8217;ll then need to instantiate and configure the table in the view, before
adding it to the context.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># tutorial/views.py</span>
<span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render</span>
<span class="kn">from</span> <span class="nn">django_tables2</span>   <span class="kn">import</span> <span class="n">RequestConfig</span>
<span class="kn">from</span> <span class="nn">tutorial.models</span>  <span class="kn">import</span> <span class="n">Person</span>
<span class="kn">from</span> <span class="nn">tutorial.tables</span>  <span class="kn">import</span> <span class="n">PersonTable</span>

<span class="k">def</span> <span class="nf">people</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">table</span> <span class="o">=</span> <span class="n">PersonTable</span><span class="p">(</span><span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>
    <span class="n">RequestConfig</span><span class="p">(</span><span class="n">request</span><span class="p">)</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s">&#39;people.html&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;table&#39;</span><span class="p">:</span> <span class="n">table</span><span class="p">})</span>
</pre></div>
</div>
<p>Using <a class="reference internal" href="#django_tables2.config.RequestConfig" title="django_tables2.config.RequestConfig"><tt class="xref py py-obj docutils literal"><span class="pre">RequestConfig</span></tt></a> automatically pulls values from <tt class="docutils literal"><span class="pre">request.GET</span></tt> and
updates the table accordingly. This enables data ordering and pagination.</p>
<p>Rather than passing a queryset to <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">render_table</span> <span class="pre">%}</span></tt>, instead pass the
table.</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">render_table</span> <span class="nv">table</span> <span class="cp">%}</span><span class="x"></span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><tt class="docutils literal"><span class="pre">{%</span> <span class="pre">render_table</span> <span class="pre">%}</span></tt> works best when it&#8217;s used in a template that
contains the current request in the context as <tt class="docutils literal"><span class="pre">request</span></tt>. The easiest way
to enable this, is to ensure that the <tt class="docutils literal"><span class="pre">TEMPLATE_CONTEXT_PROCESSORS</span></tt>
setting contains <tt class="docutils literal"><span class="pre">&quot;django.core.context_processors.request&quot;</span></tt>.</p>
</div>
<p>At this point you haven&#8217;t actually customised anything, you&#8217;ve merely added the
boilerplate code that <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">render_table</span> <span class="pre">%}</span></tt> does for you when given a
queryset. The remaining sections in this document describe how to change
various aspects of the table.</p>
</div>
<div class="section" id="populating-a-table-with-data">
<span id="table-data"></span><h2>Populating a table with data<a class="headerlink" href="#populating-a-table-with-data" title="Permalink to this headline"></a></h2>
<p>Tables are compatible with a range of input data structures. If you&#8217;ve seen the
tutorial you&#8217;ll have seen a queryset being used, however any iterable that
supports <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#len" title="(in Python v2.7)"><tt class="xref py py-func docutils literal"><span class="pre">len()</span></tt></a> and contains items that expose key-based accessed to
column values is fine.</p>
<p>An an example we&#8217;ll demonstrate using list of dicts. When defining a table it&#8217;s
necessary to declare each column. If your data matches the fields in a model,
columns can be declared automatically for you via the <a class="reference internal" href="#Table.Meta.model" title="Table.Meta.model"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta.model</span></tt></a>
option, but for non-queryset data you&#8217;ll probably want to declare
them manually:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">django_tables2</span> <span class="kn">as</span> <span class="nn">tables</span>

<span class="n">data</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">{</span><span class="s">&quot;name&quot;</span><span class="p">:</span> <span class="s">&quot;Bradley&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&quot;name&quot;</span><span class="p">:</span> <span class="s">&quot;Stevie&quot;</span><span class="p">},</span>
<span class="p">]</span>

<span class="k">class</span> <span class="nc">NameTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>

<span class="n">table</span> <span class="o">=</span> <span class="n">NameTable</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<p>You can use this technique to override columns that were automatically created
via <a class="reference internal" href="#Table.Meta.model" title="Table.Meta.model"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta.model</span></tt></a> too:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># models.py</span>
<span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>


<span class="c"># tables.py</span>
<span class="kn">import</span> <span class="nn">django_tables2</span> <span class="kn">as</span> <span class="nn">tables</span>
<span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">Person</span>

<span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s">&quot;full name&quot;</span><span class="p">)</span>

    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">Person</span>
</pre></div>
</div>
</div>
<div class="section" id="specifying-alternative-data-for-a-column">
<span id="accessors"></span><h2>Specifying alternative data for a column<a class="headerlink" href="#specifying-alternative-data-for-a-column" title="Permalink to this headline"></a></h2>
<p>Each column has a &#8220;key&#8221; that describes which value to pull from each record to
populate the column&#8217;s cells. By default, this key is just the name given to the
column, but it can be changed to allow foreign key traversal or other complex
cases.</p>
<p>To reduce ambiguity, rather than calling it a &#8220;key&#8221;, it&#8217;s been given the
special name &#8220;accessor&#8221;.</p>
<p>Accessors are just dotted paths that describe how an object should be traversed
to reach a specific value. To demonstrate how they work we&#8217;ll use them
directly:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django_tables2</span> <span class="kn">import</span> <span class="n">A</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;abc&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s">&quot;one&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s">&quot;two&quot;</span><span class="p">:</span> <span class="s">&quot;three&quot;</span><span class="p">}}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">(</span><span class="s">&quot;abc.one.two&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">resolve</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">&quot;three&quot;</span>
</pre></div>
</div>
<p>Dots represent a relationships, and are attempted in this order:</p>
<ol class="arabic simple">
<li>Dictionary lookup <tt class="docutils literal"><span class="pre">a[b]</span></tt></li>
<li>Attribute lookup <tt class="docutils literal"><span class="pre">a.b</span></tt></li>
<li>List index lookup <tt class="docutils literal"><span class="pre">a[int(b)]</span></tt></li>
</ol>
<p>Then, if the value is callable, it is called and the result is used.</p>
</div>
<div class="section" id="specifying-alternative-ordering-for-a-column">
<span id="order-by-accessors"></span><h2>Specifying alternative ordering for a column<a class="headerlink" href="#specifying-alternative-ordering-for-a-column" title="Permalink to this headline"></a></h2>
<p>When using queryset data, it&#8217;s possible for a column to present a computed
value that doesn&#8217;t correspond to a column in the database. In this situation
attempting to order the column will cause a database exception.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># models.py</span>
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
    <span class="n">family_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s">u&quot;</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">first_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">family_name</span><span class="p">)</span>

<span class="c"># tables.py</span>
<span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">table</span> <span class="o">=</span> <span class="n">PersonTable</span><span class="p">(</span><span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">order_by</span> <span class="o">=</span> <span class="s">&quot;name&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">as_html</span><span class="p">()</span>
<span class="gp">...</span>
<span class="go">FieldError: Cannot resolve keyword u&#39;name&#39; into field. Choices are: first_name, family_name</span>
</pre></div>
</div>
<p>The solution is to declare which fields should be used when ordering on via the
<tt class="docutils literal"><span class="pre">order_by</span></tt> argument:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># tables.py</span>
<span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">order_by</span><span class="o">=</span><span class="p">(</span><span class="s">&quot;first_name&quot;</span><span class="p">,</span> <span class="s">&quot;family_name&quot;</span><span class="p">))</span>
</pre></div>
</div>
<p>Accessor syntax can be used for the values, but they must terminate on a model
field.</p>
<p>If ordering doesn&#8217;t make sense for a particular column, it can be disabled via
the <tt class="docutils literal"><span class="pre">orderable</span></tt> argument:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">SimpleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
    <span class="n">actions</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">orderable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="swapping-the-position-of-columns">
<span id="swapping-columns"></span><h2>Swapping the position of columns<a class="headerlink" href="#swapping-the-position-of-columns" title="Permalink to this headline"></a></h2>
<p>By default columns are positioned in the same order as they are declared,
however when mixing auto-generated columns (via <a class="reference internal" href="#Table.Meta.model" title="Table.Meta.model"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta.model</span></tt></a>) with
manually declared columns, the column sequence becomes ambiguous.</p>
<p>To resolve the ambiguity, columns sequence can be declard via the
<a class="reference internal" href="#Table.Meta.sequence" title="Table.Meta.sequence"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta.sequence</span></tt></a> option:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">selection</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">CheckBoxColumn</span><span class="p">(</span><span class="n">accessor</span><span class="o">=</span><span class="s">&quot;pk&quot;</span><span class="p">,</span> <span class="n">orderable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">Person</span>
        <span class="n">sequence</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;selection&quot;</span><span class="p">,</span> <span class="s">&quot;first_name&quot;</span><span class="p">,</span> <span class="s">&quot;last_name&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>The special value <tt class="docutils literal"><span class="pre">&quot;...&quot;</span></tt> can be used to indicate that any omitted columns
should inserted at that location. As such it can be used at most once.</p>
</div>
<div class="section" id="customising-column-headings">
<span id="column-headers"></span><h2>Customising column headings<a class="headerlink" href="#customising-column-headings" title="Permalink to this headline"></a></h2>
<p>The header cell for each column comes from <tt class="xref py py-obj docutils literal"><span class="pre">header</span></tt>. By default this
method returns a titlised version of the <a class="reference internal" href="#Column.verbose_name" title="Column.verbose_name"><tt class="xref py py-obj docutils literal"><span class="pre">verbose_name</span></tt></a>.</p>
<p>When using queryset data and a verbose name hasn&#8217;t been explicitly
defined for a column, the corresponding model field&#8217;s verbose name will be
used.</p>
<p>Consider the following:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s">&#39;model verbose name&#39;</span><span class="p">,</span> <span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">last_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">region</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;Region&#39;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Region</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">first_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">ln</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">accessor</span><span class="o">=</span><span class="s">&#39;last_name&#39;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">region_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">accessor</span><span class="o">=</span><span class="s">&#39;region.name&#39;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span> <span class="o">=</span> <span class="n">PersonTable</span><span class="p">(</span><span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="s">&#39;first_name&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">header</span>
<span class="go">u&#39;Model Verbose Name&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="s">&#39;ln&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">header</span>
<span class="go">u&#39;Last Name&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="s">&#39;region_name&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">header</span>
<span class="go">u&#39;Name&#39;</span>
</pre></div>
</div>
<p>As you can see in the last example (region name), the results are not always
desirable when an accessor is used to cross relationships. To get around this
be careful to define <a class="reference internal" href="#Column.verbose_name" title="Column.verbose_name"><tt class="xref py py-obj docutils literal"><span class="pre">Column.verbose_name</span></tt></a>.</p>
</div>
<div class="section" id="pagination">
<span id="id1"></span><h2>Pagination<a class="headerlink" href="#pagination" title="Permalink to this headline"></a></h2>
<p>Pagination is easy, just call <a class="reference internal" href="#django_tables2.tables.Table.paginate" title="django_tables2.tables.Table.paginate"><tt class="xref py py-meth docutils literal"><span class="pre">Table.paginate()</span></tt></a> and
pass in the current page number, e.g.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">people_listing</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">table</span> <span class="o">=</span> <span class="n">PeopleTable</span><span class="p">(</span><span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>
    <span class="n">table</span><span class="o">.</span><span class="n">paginate</span><span class="p">(</span><span class="n">page</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;page&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">per_page</span><span class="o">=</span><span class="mi">25</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s">&#39;people_listing.html&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;table&#39;</span><span class="p">:</span> <span class="n">table</span><span class="p">})</span>
</pre></div>
</div>
<p>If you&#8217;re using <a class="reference internal" href="#django_tables2.config.RequestConfig" title="django_tables2.config.RequestConfig"><tt class="xref py py-obj docutils literal"><span class="pre">RequestConfig</span></tt></a>, pass pagination options to the constructor,
e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">people_listing</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">table</span> <span class="o">=</span> <span class="n">PeopleTable</span><span class="p">(</span><span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">())</span>
    <span class="n">RequestConfig</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">paginate</span><span class="o">=</span><span class="p">{</span><span class="s">&quot;per_page&quot;</span><span class="p">:</span> <span class="mi">25</span><span class="p">})</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">table</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s">&#39;people_listing.html&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;table&#39;</span><span class="p">:</span> <span class="n">table</span><span class="p">})</span>
</pre></div>
</div>
</div>
<div class="section" id="custom-rendering">
<span id="id2"></span><h2>Custom rendering<a class="headerlink" href="#custom-rendering" title="Permalink to this headline"></a></h2>
<p>Various options are available for changing the way the table is <a class="reference internal" href="#term-render"><em class="xref std std-term">rendered</em></a>. Each approach has a different balance of ease-of-use and
flexibility.</p>
<div class="section" id="table-render-foo-methods">
<span id="table-render-foo"></span><h3><tt class="xref py py-meth docutils literal"><span class="pre">Table.render_FOO()</span></tt> methods<a class="headerlink" href="#table-render-foo-methods" title="Permalink to this headline"></a></h3>
<p>To change how a column is rendered, implement a <tt class="docutils literal"><span class="pre">render_FOO</span></tt> method on the
table (where <tt class="docutils literal"><span class="pre">FOO</span></tt> is the <a class="reference internal" href="#term-column-name"><em class="xref std std-term">column name</em></a>). This approach is suitable if
you have a one-off change that you don&#8217;t want to use in multiple tables.</p>
<p>Supported keyword arguments include:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">record</span></tt> &#8211; the entire record for the row from the <a class="reference internal" href="#term-table-data"><em class="xref std std-term">table data</em></a></li>
<li><tt class="docutils literal"><span class="pre">value</span></tt> &#8211; the value for the cell retrieved from the <a class="reference internal" href="#term-table-data"><em class="xref std std-term">table data</em></a></li>
<li><tt class="docutils literal"><span class="pre">column</span></tt> &#8211; the <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> object</li>
<li><tt class="docutils literal"><span class="pre">bound_column</span></tt> &#8211; the <a class="reference internal" href="internal.html#django_tables2.columns.BoundColumn" title="django_tables2.columns.BoundColumn"><tt class="xref py py-obj docutils literal"><span class="pre">BoundColumn</span></tt></a> object</li>
<li><tt class="docutils literal"><span class="pre">bound_row</span></tt> &#8211; the <a class="reference internal" href="internal.html#django_tables2.rows.BoundRow" title="django_tables2.rows.BoundRow"><tt class="xref py py-obj docutils literal"><span class="pre">BoundRow</span></tt></a> object</li>
<li><tt class="docutils literal"><span class="pre">table</span></tt> &#8211; alias for <tt class="docutils literal"><span class="pre">self</span></tt></li>
</ul>
<p>Here&#8217;s an example where the first column displays the current row number:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">django_tables2</span> <span class="kn">as</span> <span class="nn">tables</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">itertools</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">SimpleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">row_number</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">empty_values</span><span class="o">=</span><span class="p">())</span>
<span class="gp">... </span>    <span class="nb">id</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">age</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="gp">... </span>        <span class="nb">super</span><span class="p">(</span><span class="n">SimpleTable</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="gp">... </span>        <span class="bp">self</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="n">itertools</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">render_row_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="s">&#39;Row </span><span class="si">%d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="nb">next</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">counter</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">render_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="s">&#39;&lt;</span><span class="si">%s</span><span class="s">&gt;&#39;</span> <span class="o">%</span> <span class="n">value</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span> <span class="o">=</span> <span class="n">SimpleTable</span><span class="p">([{</span><span class="s">&#39;age&#39;</span><span class="p">:</span> <span class="mi">31</span><span class="p">,</span> <span class="s">&#39;id&#39;</span><span class="p">:</span> <span class="mi">10</span><span class="p">},</span> <span class="p">{</span><span class="s">&#39;age&#39;</span><span class="p">:</span> <span class="mi">34</span><span class="p">,</span> <span class="s">&#39;id&#39;</span><span class="p">:</span> <span class="mi">11</span><span class="p">}])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">cell</span> <span class="ow">in</span> <span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
<span class="gp">... </span>    <span class="k">print</span> <span class="n">cell</span>
<span class="gp">...</span>
<span class="go">Row 0</span>
<span class="go">&lt;10&gt;</span>
<span class="go">31</span>
</pre></div>
</div>
<p>Python&#8217;s <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/inspect.html#inspect.getargspec" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">inspect.getargspec</span></tt></a> is used to only pass the arguments declared by the
function. This means it&#8217;s not necessary to add a catch all (<tt class="docutils literal"><span class="pre">**</span></tt>) keyword
argument.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last"><tt class="xref py py-obj docutils literal"><span class="pre">render</span></tt> methods are <em>only</em> called if the value for a cell is determined to
be not an <a class="reference internal" href="#term-empty-value"><em class="xref std std-term">empty value</em></a>. When a value is in <tt class="xref py py-obj docutils literal"><span class="pre">Column.empty_values</span></tt>,
a default value is rendered instead (both <tt class="xref py py-obj docutils literal"><span class="pre">Column.render</span></tt> and
<tt class="docutils literal"><span class="pre">Table.render_FOO</span></tt> are skipped).</p>
</div>
</div>
<div class="section" id="subclassing-column">
<span id="id3"></span><h3>Subclassing <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a><a class="headerlink" href="#subclassing-column" title="Permalink to this headline"></a></h3>
<p>Defining a column subclass allows functionality to be reused across tables.
Columns have a <tt class="xref py py-obj docutils literal"><span class="pre">render</span></tt> method that behaves the same as <a class="reference internal" href="#table-render-foo"><em>Table.render_FOO() methods</em></a>
methods on tables:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">django_tables2</span> <span class="kn">as</span> <span class="nn">tables</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">UpperColumn</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="n">value</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Example</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">normal</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">upper</span> <span class="o">=</span> <span class="n">UpperColumn</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="p">[{</span><span class="s">&#39;normal&#39;</span><span class="p">:</span> <span class="s">&#39;Hi there!&#39;</span><span class="p">,</span>
<span class="gp">... </span>         <span class="s">&#39;upper&#39;</span><span class="p">:</span>  <span class="s">&#39;Hi there!&#39;</span><span class="p">}]</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span> <span class="o">=</span> <span class="n">Example</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">as_html</span><span class="p">()</span>
<span class="go">u&#39;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Normal&lt;/th&gt;&lt;th&gt;Upper&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Hi there!&lt;/td&gt;&lt;td&gt;HI THERE!&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;\n&#39;</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="#table-render-foo"><em>Table.render_FOO() methods</em></a> for a list of arguments that can be accepted.</p>
<p>For complicated columns, you may want to return HTML from the
<tt class="xref py py-meth docutils literal"><span class="pre">render()</span></tt> method. This is fine, but be sure to mark the string as
safe to avoid it being escaped:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.utils.safestring</span> <span class="kn">import</span> <span class="n">mark_safe</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.utils.html</span> <span class="kn">import</span> <span class="n">escape</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">ImageColumn</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="n">mark_safe</span><span class="p">(</span><span class="s">&#39;&lt;img src=&quot;/media/img/</span><span class="si">%s</span><span class="s">.jpg&quot; /&gt;&#39;</span>
<span class="gp">... </span>                         <span class="o">%</span> <span class="n">escape</span><span class="p">(</span><span class="n">value</span><span class="p">))</span>
<span class="gp">...</span>
</pre></div>
</div>
</div>
<div class="section" id="css">
<span id="id4"></span><h3>CSS<a class="headerlink" href="#css" title="Permalink to this headline"></a></h3>
<p>In order to use CSS to style a table, you&#8217;ll probably want to add a
<tt class="docutils literal"><span class="pre">class</span></tt> or <tt class="docutils literal"><span class="pre">id</span></tt> attribute to the <tt class="docutils literal"><span class="pre">&lt;table&gt;</span></tt> element. django-tables2 has
a hook that allows abitrary attributes to be added to the <tt class="docutils literal"><span class="pre">&lt;table&gt;</span></tt> tag.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">django_tables2</span> <span class="kn">as</span> <span class="nn">tables</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">SimpleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="nb">id</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">age</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="gp">... </span>        <span class="n">attrs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;class&#39;</span><span class="p">:</span> <span class="s">&#39;mytable&#39;</span><span class="p">}</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span> <span class="o">=</span> <span class="n">SimpleTable</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">as_html</span><span class="p">()</span>
<span class="go">&#39;&lt;table class=&quot;mytable&quot;&gt;...&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="custom-template">
<span id="id5"></span><h3>Custom Template<a class="headerlink" href="#custom-template" title="Permalink to this headline"></a></h3>
<p>And of course if you want full control over the way the table is rendered,
ignore the built-in generation tools, and instead pass an instance of your
<a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a> subclass into your own template, and render it yourself.</p>
<p>Have a look at the <tt class="docutils literal"><span class="pre">django_tables2/table.html</span></tt> template for an example.</p>
</div>
</div>
<div class="section" id="querystring-fields">
<span id="query-string-fields"></span><h2>Querystring fields<a class="headerlink" href="#querystring-fields" title="Permalink to this headline"></a></h2>
<p>Tables pass data via the querystring to indicate ordering and pagination
preferences.</p>
<p>The names of the querystring variables are configurable via the options:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">order_by_field</span></tt> &#8211; default: <tt class="docutils literal"><span class="pre">&quot;sort&quot;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">page_field</span></tt> &#8211; default: <tt class="docutils literal"><span class="pre">&quot;page&quot;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">per_page_field</span></tt> &#8211; default: <tt class="docutils literal"><span class="pre">&quot;per_page&quot;</span></tt>, <strong>note:</strong> this field currently
isn&#8217;t used by <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">render_table</span> <span class="pre">%}</span></tt></li>
</ul>
<p>Each of these can be specified in three places:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">Table.Meta.foo</span></tt></li>
<li><tt class="docutils literal"><span class="pre">Table(...,</span> <span class="pre">foo=...)</span></tt></li>
<li><tt class="docutils literal"><span class="pre">Table(...).foo</span> <span class="pre">=</span> <span class="pre">...</span></tt></li>
</ul>
<p>If you&#8217;re using multiple tables on a single page, you&#8217;ll want to prefix these
fields with a table-specific name. e.g.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">people_listing</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">config</span> <span class="o">=</span> <span class="n">RequestConfig</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
    <span class="n">table1</span> <span class="o">=</span> <span class="n">PeopleTable</span><span class="p">(</span><span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">(),</span> <span class="n">prefix</span><span class="o">=</span><span class="s">&quot;1-&quot;</span><span class="p">)</span>  <span class="c"># prefix specified</span>
    <span class="n">table2</span> <span class="o">=</span> <span class="n">PeopleTable</span><span class="p">(</span><span class="n">Person</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">(),</span> <span class="n">prefix</span><span class="o">=</span><span class="s">&quot;2-&quot;</span><span class="p">)</span>  <span class="c"># prefix specified</span>
    <span class="n">config</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">table1</span><span class="p">)</span>
    <span class="n">config</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">table2</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s">&quot;people_listing.html&quot;</span><span class="p">,</span>
                  <span class="p">{</span><span class="s">&quot;table1&quot;</span><span class="p">:</span> <span class="n">table1</span><span class="p">,</span> <span class="s">&quot;table2&quot;</span><span class="p">:</span> <span class="n">table2</span><span class="p">})</span>
</pre></div>
</div>
</div>
<div class="section" id="column-attributes">
<span id="id6"></span><h2>Column attributes<a class="headerlink" href="#column-attributes" title="Permalink to this headline"></a></h2>
<p>Column attributes can be specified using the <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a> with specific keys.
The dict defines HTML attributes for one of more elements within the column.
Depending on the column, different elements are supported, however <tt class="docutils literal"><span class="pre">th</span></tt>,
<tt class="docutils literal"><span class="pre">td</span></tt>, and <tt class="docutils literal"><span class="pre">cell</span></tt> are supported universally.</p>
<p>e.g.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">django_tables2</span> <span class="kn">as</span> <span class="nn">tables</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">SimpleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="p">{</span><span class="s">&quot;th&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s">&quot;id&quot;</span><span class="p">:</span> <span class="s">&quot;foo&quot;</span><span class="p">}})</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">SimpleTable</span><span class="p">(</span><span class="n">data</span><span class="p">)</span><span class="o">.</span><span class="n">as_html</span><span class="p">()</span>
<span class="go">&quot;{snip}&lt;thead&gt;&lt;tr&gt;&lt;th id=&quot;foo&quot; class=&quot;name&quot;&gt;{snip}&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;name&quot;&gt;{snip}&quot;</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">th</span></tt> and <tt class="docutils literal"><span class="pre">td</span></tt> are special cases because they&#8217;re extended during rendering
to add the column name as a class. This is done to make writing CSS easier.
Have a look at each column&#8217;s API reference to find which elements are
supported.</p>
</div>
<div class="section" id="built-in-columns">
<span id="builtin-columns"></span><h2>Built-in columns<a class="headerlink" href="#built-in-columns" title="Permalink to this headline"></a></h2>
<p>For common use-cases the following columns are included:</p>
<ul class="simple">
<li><a class="reference internal" href="#django_tables2.columns.BooleanColumn" title="django_tables2.columns.BooleanColumn"><tt class="xref py py-obj docutils literal"><span class="pre">BooleanColumn</span></tt></a> &#8211; renders boolean values</li>
<li><a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> &#8211; generic column</li>
<li><a class="reference internal" href="#django_tables2.columns.CheckBoxColumn" title="django_tables2.columns.CheckBoxColumn"><tt class="xref py py-obj docutils literal"><span class="pre">CheckBoxColumn</span></tt></a> &#8211; renders checkbox form inputs</li>
<li><a class="reference internal" href="#django_tables2.columns.DateColumn" title="django_tables2.columns.DateColumn"><tt class="xref py py-obj docutils literal"><span class="pre">DateColumn</span></tt></a> &#8211; date formatting</li>
<li><a class="reference internal" href="#django_tables2.columns.DateTimeColumn" title="django_tables2.columns.DateTimeColumn"><tt class="xref py py-obj docutils literal"><span class="pre">DateTimeColumn</span></tt></a> &#8211; datetime formatting in the local timezone</li>
<li><a class="reference internal" href="#django_tables2.columns.FileColumn" title="django_tables2.columns.FileColumn"><tt class="xref py py-obj docutils literal"><span class="pre">FileColumn</span></tt></a> &#8211; renders files as links</li>
<li><a class="reference internal" href="#django_tables2.columns.EmailColumn" title="django_tables2.columns.EmailColumn"><tt class="xref py py-obj docutils literal"><span class="pre">EmailColumn</span></tt></a> &#8211; renders <tt class="docutils literal"><span class="pre">&lt;a</span> <span class="pre">href=&quot;mailto:...&quot;&gt;</span></tt> tags</li>
<li><a class="reference internal" href="#django_tables2.columns.LinkColumn" title="django_tables2.columns.LinkColumn"><tt class="xref py py-obj docutils literal"><span class="pre">LinkColumn</span></tt></a> &#8211; renders <tt class="docutils literal"><span class="pre">&lt;a</span> <span class="pre">href=&quot;...&quot;&gt;</span></tt> tags (absolute url)</li>
<li><a class="reference internal" href="#django_tables2.columns.TemplateColumn" title="django_tables2.columns.TemplateColumn"><tt class="xref py py-obj docutils literal"><span class="pre">TemplateColumn</span></tt></a> &#8211; renders template code</li>
<li><a class="reference internal" href="#django_tables2.columns.URLColumn" title="django_tables2.columns.URLColumn"><tt class="xref py py-obj docutils literal"><span class="pre">URLColumn</span></tt></a> &#8211; renders <tt class="docutils literal"><span class="pre">&lt;a</span> <span class="pre">href=&quot;...&quot;&gt;</span></tt> tags (compose a django url)</li>
</ul>
</div>
<div class="section" id="template-tags">
<span id="id7"></span><h2>Template tags<a class="headerlink" href="#template-tags" title="Permalink to this headline"></a></h2>
<div class="section" id="render-table">
<span id="template-tags-render-table"></span><h3>render_table<a class="headerlink" href="#render-table" title="Permalink to this headline"></a></h3>
<p>Renders a <a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a> object to HTML and enables as
many features in the output as possible.</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">django_tables2</span> <span class="cp">%}</span><span class="x"></span>
<span class="cp">{%</span> <span class="k">render_table</span> <span class="nv">table</span> <span class="cp">%}</span><span class="x"></span>

<span class="c">{# Alternatively a specific template can be used #}</span><span class="x"></span>
<span class="cp">{%</span> <span class="k">render_table</span> <span class="nv">table</span> <span class="s2">&quot;path/to/custom_table_template.html&quot;</span> <span class="cp">%}</span><span class="x"></span>
</pre></div>
</div>
<p>If the second argument (template path) is given, the template will be rendered
with a <tt class="xref py py-obj docutils literal"><span class="pre">RequestContext</span></tt> and the table will be in the variable <tt class="docutils literal"><span class="pre">table</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This tag temporarily modifies the <a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a> object while it is being
rendered. It adds a <tt class="docutils literal"><span class="pre">request</span></tt> attribute to the table, which allows
<a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> objects to have access to a <tt class="xref py py-obj docutils literal"><span class="pre">RequestContext</span></tt>. See
<a class="reference internal" href="#django_tables2.columns.TemplateColumn" title="django_tables2.columns.TemplateColumn"><tt class="xref py py-obj docutils literal"><span class="pre">TemplateColumn</span></tt></a> for an example.</p>
</div>
<p>This tag requires that the template in which it&#8217;s rendered contains the
<tt class="xref py py-obj docutils literal"><span class="pre">HttpRequest</span></tt> inside a <tt class="docutils literal"><span class="pre">request</span></tt> variable. This can be achieved by ensuring
the <tt class="docutils literal"><span class="pre">TEMPLATE_CONTEXT_PROCESSORS</span></tt> setting contains
<tt class="docutils literal"><span class="pre">&quot;django.core.context_processors.request&quot;</span></tt>. By default it is not included,
and the setting itself is not even defined within your project&#8217;s
<tt class="docutils literal"><span class="pre">settings.py</span></tt>. To resolve this simply add the following to your
<tt class="docutils literal"><span class="pre">settings.py</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">TEMPLATE_CONTEXT_PROCESSORS</span> <span class="o">=</span> <span class="p">(</span>
    <span class="s">&quot;django.contrib.auth.context_processors.auth&quot;</span><span class="p">,</span>
    <span class="s">&quot;django.core.context_processors.debug&quot;</span><span class="p">,</span>
    <span class="s">&quot;django.core.context_processors.i18n&quot;</span><span class="p">,</span>
    <span class="s">&quot;django.core.context_processors.media&quot;</span><span class="p">,</span>
    <span class="s">&quot;django.core.context_processors.static&quot;</span><span class="p">,</span>
    <span class="s">&quot;django.contrib.messages.context_processors.messages&quot;</span><span class="p">,</span>
    <span class="s">&quot;django.core.context_processors.request&quot;</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="querystring">
<span id="template-tags-querystring"></span><h3>querystring<a class="headerlink" href="#querystring" title="Permalink to this headline"></a></h3>
<p>A utility that allows you to update a portion of the query-string without
overwriting the entire thing.</p>
<p>Let&#8217;s assume we have the querystring <tt class="docutils literal"><span class="pre">?search=pirates&amp;sort=name&amp;page=5</span></tt> and
we want to update the <tt class="docutils literal"><span class="pre">sort</span></tt> parameter:</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">querystring</span> <span class="s2">&quot;sort&quot;</span><span class="o">=</span><span class="s2">&quot;dob&quot;</span> <span class="cp">%}</span><span class="x">           # ?search=pirates&amp;sort=dob&amp;page=5</span>
<span class="cp">{%</span> <span class="k">querystring</span> <span class="s2">&quot;sort&quot;</span><span class="o">=</span><span class="s2">&quot;&quot;</span> <span class="cp">%}</span><span class="x">              # ?search=pirates&amp;page=5</span>
<span class="cp">{%</span> <span class="k">querystring</span> <span class="s2">&quot;sort&quot;</span><span class="o">=</span><span class="s2">&quot;&quot;</span> <span class="s2">&quot;search&quot;</span><span class="o">=</span><span class="s2">&quot;&quot;</span> <span class="cp">%}</span><span class="x">  # ?page=5</span>

<span class="cp">{%</span> <span class="k">with</span> <span class="s2">&quot;search&quot;</span> <span class="k">as</span> <span class="nv">key</span> <span class="cp">%}</span><span class="x">               # supports variables as keys</span>
<span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">key</span><span class="o">=</span><span class="s2">&quot;robots&quot;</span> <span class="cp">%}</span><span class="x">           # ?search=robots&amp;page=5</span>
<span class="cp">{%</span> <span class="k">endwith</span> <span class="cp">%}</span><span class="x"></span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="template-filters">
<h2>Template filters<a class="headerlink" href="#template-filters" title="Permalink to this headline"></a></h2>
<div class="section" id="title">
<h3>title<a class="headerlink" href="#title" title="Permalink to this headline"></a></h3>
<p>String filter that performs title case conversion on a per-word basis, leaving
words containing upper-case letters alone.</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{{</span> <span class="s2">&quot;start 6PM&quot;</span><span class="o">|</span><span class="nf">title</span> <span class="cp">}}</span><span class="x">   # Start 6PM</span>
<span class="cp">{{</span> <span class="s2">&quot;sTart 6pm&quot;</span><span class="o">|</span><span class="nf">title</span> <span class="cp">}}</span><span class="x">   # sTart 6pm</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Be careful when loading the <tt class="docutils literal"><span class="pre">django_tables2</span></tt> template library to not
in advertantly load <tt class="docutils literal"><span class="pre">title</span></tt>. You should always use the
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">...</span> <span class="pre">from</span> <span class="pre">...</span> <span class="pre">%}</span></tt> syntax.</p>
</div>
</div>
</div>
<div class="section" id="class-based-generic-mixins">
<h2>Class Based Generic Mixins<a class="headerlink" href="#class-based-generic-mixins" title="Permalink to this headline"></a></h2>
<p>Django 1.3 introduced <a class="reference external" href="https://docs.djangoproject.com/en/1.3/topics/class-based-views/">class based views</a> as a mechanism to reduce the
repetition in view code. django-tables2 comes with a single class based view
mixin: <tt class="xref py py-obj docutils literal"><span class="pre">SingleTableMixin</span></tt>. It makes it trivial to incorporate a table into a
view/template.</p>
<p>The following view parameters are supported:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">table_class</span></tt> –- the table class to use, e.g. <tt class="docutils literal"><span class="pre">SimpleTable</span></tt></li>
<li><tt class="docutils literal"><span class="pre">table_data</span></tt> (or <tt class="docutils literal"><span class="pre">get_table_data()</span></tt>) &#8211; the data used to populate the table</li>
<li><tt class="docutils literal"><span class="pre">context_table_name</span></tt> &#8211; the name of template variable containing the table object</li>
<li><tt class="docutils literal"><span class="pre">table_pagination</span></tt> &#8211; pagination options to pass to <a class="reference internal" href="#django_tables2.config.RequestConfig" title="django_tables2.config.RequestConfig"><tt class="xref py py-obj docutils literal"><span class="pre">RequestConfig</span></tt></a></li>
</ul>
<p>For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django_tables2</span> <span class="kn">import</span> <span class="n">SingleTableView</span>


<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
    <span class="n">last_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">Simple</span>


<span class="k">class</span> <span class="nc">PersonList</span><span class="p">(</span><span class="n">SingleTableView</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Person</span>
    <span class="n">table_class</span> <span class="o">=</span> <span class="n">PersonTable</span>
</pre></div>
</div>
<p>The template could then be as simple as:</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">render_table</span> <span class="nv">from</span> <span class="nv">django_tables2</span> <span class="cp">%}</span><span class="x"></span>
<span class="cp">{%</span> <span class="k">render_table</span> <span class="nv">table</span> <span class="cp">%}</span><span class="x"></span>
</pre></div>
</div>
<p>Such little code is possible due to the example above taking advantage of
default values and <tt class="xref py py-obj docutils literal"><span class="pre">SimpleTableMixin</span></tt>&#8216;s eagarness at finding data sources
when one isn&#8217;t explicitly defined.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you need more than one table on a page, use <tt class="xref py py-obj docutils literal"><span class="pre">SingleTableView</span></tt> and use
<tt class="xref py py-obj docutils literal"><span class="pre">get_context_data</span></tt> to initialise the other tables and add them to the
context.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You don&#8217;t have to base your view on <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/class-based-views/flattened-index.html#ListView" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">ListView</span></tt></a>, you&#8217;re able to mix
<tt class="xref py py-obj docutils literal"><span class="pre">SingleTableMixin</span></tt> directly.</p>
</div>
</div>
<div class="section" id="table-mixins">
<h2>Table Mixins<a class="headerlink" href="#table-mixins" title="Permalink to this headline"></a></h2>
<p>It&#8217;s possible to create a mixin for a table that overrides something, however
unless it itself is a subclass of <a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a> class variable instances of
<a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> will <strong>not</strong> be added to the class which is using the mixin.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">UselessMixin</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">extra</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">TestTable</span><span class="p">(</span><span class="n">UselessMixin</span><span class="p">,</span> <span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">TestTable</span><span class="o">.</span><span class="n">base_columns</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">[&#39;name&#39;]</span>
</pre></div>
</div>
<p>To have a mixin contribute a column, it needs to be a subclass of
<a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a>. With this in mind the previous example
<em>should</em> have been written as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">UsefulMixin</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">extra</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">TestTable</span><span class="p">(</span><span class="n">UsefulMixin</span><span class="p">,</span> <span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">TestTable</span><span class="o">.</span><span class="n">base_columns</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">[&#39;extra&#39;, &#39;name&#39;]</span>
</pre></div>
</div>
</div>
<div class="section" id="tables-for-models">
<span id="id9"></span><h2>Tables for models<a class="headerlink" href="#tables-for-models" title="Permalink to this headline"></a></h2>
<p>If you build use tables to display <tt class="xref py py-obj docutils literal"><span class="pre">QuerySet</span></tt> data, rather than defining each
column manually in the table, the <a class="reference internal" href="#Table.Meta.model" title="Table.Meta.model"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta.model</span></tt></a> option allows tables to
be dynamically created based on a model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># models.py</span>
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
    <span class="n">last_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
    <span class="n">user</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="s">&quot;auth.User&quot;</span><span class="p">)</span>
    <span class="n">dob</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateField</span><span class="p">()</span>

<span class="c"># tables.py</span>
<span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">Person</span>
</pre></div>
</div>
<p>This has a number of benefits:</p>
<ul class="simple">
<li>Less code, easier to write, more DRY</li>
<li>Columns use the field&#8217;s <tt class="xref py py-obj docutils literal"><span class="pre">verbose_name</span></tt></li>
<li>Specialised columns are used where possible (e.g. <a class="reference internal" href="#django_tables2.columns.DateColumn" title="django_tables2.columns.DateColumn"><tt class="xref py py-obj docutils literal"><span class="pre">DateColumn</span></tt></a> for a
<tt class="xref py py-obj docutils literal"><span class="pre">DateField</span></tt>)</li>
</ul>
<p>When using this approach, the following options are useful:</p>
<ul class="simple">
<li><a class="reference internal" href="#Table.Meta.sequence" title="Table.Meta.sequence"><tt class="xref py py-obj docutils literal"><span class="pre">sequence</span></tt></a> &#8211; reorder columns</li>
<li><a class="reference internal" href="#Table.Meta.fields" title="Table.Meta.fields"><tt class="xref py py-obj docutils literal"><span class="pre">fields</span></tt></a> &#8211; specify model fields to <em>include</em></li>
<li><a class="reference internal" href="#Table.Meta.exclude" title="Table.Meta.exclude"><tt class="xref py py-obj docutils literal"><span class="pre">exclude</span></tt></a> &#8211; specify model fields to <em>excluse</em></li>
</ul>
</div>
<div class="section" id="api-reference">
<h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline"></a></h2>
<div class="section" id="accessor-a">
<h3><a class="reference internal" href="#django_tables2.utils.Accessor" title="django_tables2.utils.Accessor"><tt class="xref py py-obj docutils literal"><span class="pre">Accessor</span></tt></a> (<tt class="xref py py-obj docutils literal"><span class="pre">A</span></tt>)<a class="headerlink" href="#accessor-a" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.utils.Accessor">
<em class="property">class </em><tt class="descclassname">django_tables2.utils.</tt><tt class="descname">Accessor</tt><a class="reference internal" href="_modules/django_tables2/utils.html#Accessor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_tables2.utils.Accessor" title="Permalink to this definition"></a></dt>
<dd><p>A string describing a path from one object to another via attribute/index
accesses. For convenience, the class has an alias <tt class="xref py py-obj docutils literal"><span class="pre">A</span></tt> to allow for more concise code.</p>
<p>Relations are separated by a <tt class="docutils literal"><span class="pre">.</span></tt> character.</p>
</dd></dl>

</div>
<div class="section" id="requestconfig">
<h3><a class="reference internal" href="#django_tables2.config.RequestConfig" title="django_tables2.config.RequestConfig"><tt class="xref py py-obj docutils literal"><span class="pre">RequestConfig</span></tt></a><a class="headerlink" href="#requestconfig" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.config.RequestConfig">
<em class="property">class </em><tt class="descclassname">django_tables2.config.</tt><tt class="descname">RequestConfig</tt><big>(</big><em>request</em>, <em>paginate=True</em><big>)</big><a class="reference internal" href="_modules/django_tables2/config.html#RequestConfig"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_tables2.config.RequestConfig" title="Permalink to this definition"></a></dt>
<dd><p>A configurator that uses request data to setup a table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>paginate</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a> or <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a>) &#8211; <p>indicates whether to paginate, and if so, what default
values to use. If the value evaluates to <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#False" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">False</span></tt></a>,
pagination will be disabled. A <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a> can be used to
specify default values for the call to
<a class="reference internal" href="#django_tables2.tables.Table.paginate" title="django_tables2.tables.Table.paginate"><tt class="xref py py-obj docutils literal"><span class="pre">paginate</span></tt></a> (e.g. to define a default
<em>per_page</em> value).</p>
<p>A special <em>silent</em> item can be used to enable automatic
handling of pagination exceptions using the following
algorithm:</p>
<ul class="simple">
<li>If <tt class="xref py py-obj docutils literal"><span class="pre">PageNotAnInteger`</span></tt> is raised,
show the first page.</li>
<li>If <a class="reference external" href="/usr/share/doc/python-django-doc/html/topics/pagination.html#django.core.paginator.EmptyPage" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">EmptyPage</span></tt></a> is raised, show
the last page.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="table">
<h3><a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a><a class="headerlink" href="#table" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.tables.Table">
<em class="property">class </em><tt class="descclassname">django_tables2.tables.</tt><tt class="descname">Table</tt><big>(</big><em>data</em>, <em>order_by=None</em>, <em>orderable=None</em>, <em>empty_text=None</em>, <em>exclude=None</em>, <em>attrs=None</em>, <em>sequence=None</em>, <em>prefix=None</em>, <em>order_by_field=None</em>, <em>page_field=None</em>, <em>per_page_field=None</em>, <em>template=None</em>, <em>sortable=None</em>, <em>default=None</em><big>)</big><a class="reference internal" href="_modules/django_tables2/tables.html#Table"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_tables2.tables.Table" title="Permalink to this definition"></a></dt>
<dd><p>A representation of a table.</p>
<dl class="attribute">
<dt id="Table.attrs">
<tt class="descname">attrs</tt><a class="headerlink" href="#Table.attrs" title="Permalink to this definition"></a></dt>
<dd><p>HTML attributes to add to the <tt class="docutils literal"><span class="pre">&lt;table&gt;</span></tt> tag.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a></td>
</tr>
</tbody>
</table>
<p>When accessing the attribute, the value is always returned as an
<tt class="xref py py-obj docutils literal"><span class="pre">AttributeDict</span></tt> to allow easily conversion to HTML.</p>
</dd></dl>

<dl class="attribute">
<dt id="Table.columns">
<tt class="descname">columns</tt><a class="headerlink" href="#Table.columns" title="Permalink to this definition"></a></dt>
<dd><p>The columns in the table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference internal" href="internal.html#django_tables2.columns.BoundColumns" title="django_tables2.columns.BoundColumns"><tt class="xref py py-obj docutils literal"><span class="pre">BoundColumns</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.default">
<tt class="descname">default</tt><a class="headerlink" href="#Table.default" title="Permalink to this definition"></a></dt>
<dd><p>Text to render in empty cells (determined by <tt class="xref py py-obj docutils literal"><span class="pre">Column.empty_values</span></tt>,
default <tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta.default</span></tt>)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.empty_text">
<tt class="descname">empty_text</tt><a class="headerlink" href="#Table.empty_text" title="Permalink to this definition"></a></dt>
<dd><p>Empty text to render when the table has no data. (default
<a class="reference internal" href="#Table.Meta.empty_text" title="Table.Meta.empty_text"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta.empty_text</span></tt></a>)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.exclude">
<tt class="descname">exclude</tt><a class="headerlink" href="#Table.exclude" title="Permalink to this definition"></a></dt>
<dd><p>The names of columns that shouldn&#8217;t be included in the table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body">iterable of <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.order_by_field">
<tt class="descname">order_by_field</tt><a class="headerlink" href="#Table.order_by_field" title="Permalink to this definition"></a></dt>
<dd><p>If not <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a>, defines the name of the <em>order by</em> querystring field.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.page">
<tt class="descname">page</tt><a class="headerlink" href="#Table.page" title="Permalink to this definition"></a></dt>
<dd><p>The current page in the context of pagination.</p>
<p>Added during the call to <a class="reference internal" href="#django_tables2.tables.Table.paginate" title="django_tables2.tables.Table.paginate"><tt class="xref py py-obj docutils literal"><span class="pre">Table.paginate</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="Table.page_field">
<tt class="descname">page_field</tt><a class="headerlink" href="#Table.page_field" title="Permalink to this definition"></a></dt>
<dd><p>If not <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a>, defines the name of the <em>current page</em> querystring
field.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.paginator">
<tt class="descname">paginator</tt><a class="headerlink" href="#Table.paginator" title="Permalink to this definition"></a></dt>
<dd><p>The current paginator for the table.</p>
<p>Added during the call to <a class="reference internal" href="#django_tables2.tables.Table.paginate" title="django_tables2.tables.Table.paginate"><tt class="xref py py-obj docutils literal"><span class="pre">Table.paginate</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="Table.per_page_field">
<tt class="descname">per_page_field</tt><a class="headerlink" href="#Table.per_page_field" title="Permalink to this definition"></a></dt>
<dd><p>If not <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a>, defines the name of the <em>per page</em> querystring field.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.prefix">
<tt class="descname">prefix</tt><a class="headerlink" href="#Table.prefix" title="Permalink to this definition"></a></dt>
<dd><p>A prefix for querystring fields to avoid name-clashes when using
multiple tables on a single page.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.rows">
<tt class="descname">rows</tt><a class="headerlink" href="#Table.rows" title="Permalink to this definition"></a></dt>
<dd><p>The rows of the table (ignoring pagination).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference internal" href="internal.html#django_tables2.rows.BoundRows" title="django_tables2.rows.BoundRows"><tt class="xref py py-obj docutils literal"><span class="pre">BoundRows</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.sequence">
<tt class="descname">sequence</tt><a class="headerlink" href="#Table.sequence" title="Permalink to this definition"></a></dt>
<dd><p>The sequence/order of columns the columns (from left to right).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body">iterable</td>
</tr>
</tbody>
</table>
<p>Items in the sequence must be <a class="reference internal" href="#term-column-name"><em class="xref std std-term">column names</em></a>, or
<tt class="docutils literal"><span class="pre">&quot;...&quot;</span></tt> (string containing three periods). <tt class="docutils literal"><span class="pre">...</span></tt> can be used as a
catch-all for columns that aren&#8217;t specified.</p>
</dd></dl>

<dl class="attribute">
<dt id="Table.orderable">
<tt class="descname">orderable</tt><a class="headerlink" href="#Table.orderable" title="Permalink to this definition"></a></dt>
<dd><p>Enable/disable column ordering on this table</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Table.template">
<tt class="descname">template</tt><a class="headerlink" href="#Table.template" title="Permalink to this definition"></a></dt>
<dd><p>The template to render when using <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">render_table</span> <span class="pre">%}</span></tt> (default
<tt class="docutils literal"><span class="pre">&quot;django_tables2/table.html&quot;</span></tt>)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="django_tables2.tables.Table.paginate">
<tt class="descname">paginate</tt><big>(</big><em>klass=&lt;class 'django.core.paginator.Paginator'&gt;</em>, <em>per_page=None</em>, <em>page=1</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/django_tables2/tables.html#Table.paginate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_tables2.tables.Table.paginate" title="Permalink to this definition"></a></dt>
<dd><p>Paginates the table using a paginator and creates a <tt class="docutils literal"><span class="pre">page</span></tt> property
containing information for the current page.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>klass</strong> (<em>Paginator class</em>) &#8211; a paginator class to paginate the results</li>
<li><strong>per_page</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#int" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">int</span></tt></a>) &#8211; how many records are displayed on each page</li>
<li><strong>page</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#int" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">int</span></tt></a>) &#8211; which page should be displayed.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Extra arguments are passed to the paginator.</p>
<p>Pagination exceptions (<a class="reference external" href="/usr/share/doc/python-django-doc/html/topics/pagination.html#django.core.paginator.EmptyPage" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">EmptyPage</span></tt></a> and
<a class="reference external" href="/usr/share/doc/python-django-doc/html/topics/pagination.html#django.core.paginator.PageNotAnInteger" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">PageNotAnInteger</span></tt></a>) may be raised from this
method and should be handled by the caller.</p>
</dd></dl>

<dl class="method">
<dt id="django_tables2.tables.Table.as_html">
<tt class="descname">as_html</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/django_tables2/tables.html#Table.as_html"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_tables2.tables.Table.as_html" title="Permalink to this definition"></a></dt>
<dd><p>Render the table to a simple HTML table.</p>
<p>If this method is used in the request/response cycle, any links
generated will clobber the querystring of the request. Use the
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">render_table</span> <span class="pre">%}</span></tt> template tag instead.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="table-meta">
<h3><a class="reference internal" href="#Table.Meta" title="Table.Meta"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta</span></tt></a><a class="headerlink" href="#table-meta" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="Table.Meta">
<em class="property">class </em><tt class="descclassname">Table.</tt><tt class="descname">Meta</tt><a class="headerlink" href="#Table.Meta" title="Permalink to this definition"></a></dt>
<dd><p>Provides a way to define <em>global</em> settings for table, as opposed to
defining them for each instance.</p>
<dl class="attribute">
<dt id="Table.Meta.attrs">
<tt class="descname">attrs</tt><a class="headerlink" href="#Table.Meta.attrs" title="Permalink to this definition"></a></dt>
<dd><p>Allows custom HTML attributes to be specified which will be added to
the <tt class="docutils literal"><span class="pre">&lt;table&gt;</span></tt> tag of any table rendered via
<a class="reference internal" href="#django_tables2.tables.Table.as_html" title="django_tables2.tables.Table.as_html"><tt class="xref py py-meth docutils literal"><span class="pre">Table.as_html()</span></tt></a> or the
<a class="reference internal" href="#template-tags-render-table"><em>render_table</em></a> template tag.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><tt class="docutils literal"><span class="pre">{}</span></tt></td>
</tr>
</tbody>
</table>
<p>This is typically used to enable a theme for a table (which is done by
adding a CSS class to the <tt class="docutils literal"><span class="pre">&lt;table&gt;</span></tt> element). i.e.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">SimpleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>

    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">attrs</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;class&quot;</span><span class="p">:</span> <span class="s">&quot;paleblue&quot;</span><span class="p">}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This functionality is also available via the <tt class="docutils literal"><span class="pre">attrs</span></tt> keyword
argument to a table&#8217;s constructor.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.empty_text">
<tt class="descname">empty_text</tt><a class="headerlink" href="#Table.Meta.empty_text" title="Permalink to this definition"></a></dt>
<dd><p>Defines the text to display when the table has no rows.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a></td>
</tr>
</tbody>
</table>
<p>If the table is empty and <tt class="docutils literal"><span class="pre">bool(empty_text)</span></tt> is <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#True" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">True</span></tt></a>, a row is
displayed containing <tt class="docutils literal"><span class="pre">empty_text</span></tt>. This is allows a message such as
<em>There are currently no FOO.</em> to be displayed.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This functionality is also available via the <tt class="docutils literal"><span class="pre">empty_text</span></tt> keyword
argument to a table&#8217;s constructor.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.exclude">
<tt class="descname">exclude</tt><a class="headerlink" href="#Table.Meta.exclude" title="Permalink to this definition"></a></dt>
<dd><p>Defines which columns should be excluded from the table. This is useful
in subclasses to exclude columns in a parent.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body">tuple of <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><tt class="docutils literal"><span class="pre">()</span></tt></td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">first_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">last_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Person</span><span class="o">.</span><span class="n">base_columns</span>
<span class="go">{&#39;first_name&#39;: &lt;django_tables2.columns.Column object at 0x10046df10&gt;,</span>
<span class="go">&#39;last_name&#39;: &lt;django_tables2.columns.Column object at 0x10046d8d0&gt;}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">ForgetfulPerson</span><span class="p">(</span><span class="n">Person</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="gp">... </span>        <span class="n">exclude</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;last_name&quot;</span><span class="p">,</span> <span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ForgetfulPerson</span><span class="o">.</span><span class="n">base_columns</span>
<span class="go">{&#39;first_name&#39;: &lt;django_tables2.columns.Column object at 0x10046df10&gt;}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>This functionality is also available via the <tt class="docutils literal"><span class="pre">exclude</span></tt> keyword
argument to a table&#8217;s constructor.</p>
<p class="last">However, unlike some of the other <a class="reference internal" href="#Table.Meta" title="Table.Meta"><tt class="xref py py-obj docutils literal"><span class="pre">Table.Meta</span></tt></a> options, providing the
<tt class="docutils literal"><span class="pre">exclude</span></tt> keyword to a table&#8217;s constructor <strong>won&#8217;t override</strong> the
<a class="reference internal" href="#Table.Meta.exclude" title="Table.Meta.exclude"><tt class="xref py py-obj docutils literal"><span class="pre">Meta.exclude</span></tt></a>. Instead, it will be effectively be <em>added</em>
to it. i.e. you can&#8217;t use the constructor&#8217;s <tt class="docutils literal"><span class="pre">exclude</span></tt> argument to
<em>undo</em> an exclusion.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.fields">
<tt class="descname">fields</tt><a class="headerlink" href="#Table.Meta.fields" title="Permalink to this definition"></a></dt>
<dd><p>Used in conjunction with <a class="reference internal" href="#Table.Meta.model" title="Table.Meta.model"><tt class="xref py py-obj docutils literal"><span class="pre">model</span></tt></a>, specifies which fields
should have columns in the table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body">tuple of <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a> or <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a></td>
</tr>
</tbody>
</table>
<p>If <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a>, all fields are used, otherwise only those named.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># models.py</span>
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
    <span class="n">last_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>

<span class="c"># tables.py</span>
<span class="k">class</span> <span class="nc">PersonTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">Person</span>
        <span class="n">fields</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;first_name&quot;</span><span class="p">,</span> <span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.model">
<tt class="descname">model</tt><a class="headerlink" href="#Table.Meta.model" title="Permalink to this definition"></a></dt>
<dd><p>A model to inspect and automatically create corresponding columns.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body">Django model</td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a></td>
</tr>
</tbody>
</table>
<p>This option allows a Django model to be specified to cause the table to
automatically generate columns that correspond to the fields in a
model.</p>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.order_by">
<tt class="descname">order_by</tt><a class="headerlink" href="#Table.Meta.order_by" title="Permalink to this definition"></a></dt>
<dd><p>The default ordering. e.g. <tt class="docutils literal"><span class="pre">('name',</span> <span class="pre">'-age')</span></tt>. A hyphen <tt class="docutils literal"><span class="pre">-</span></tt> can be
used to prefix a column name to indicate <em>descending</em> order.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#tuple" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">tuple</span></tt></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><tt class="docutils literal"><span class="pre">()</span></tt></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This functionality is also available via the <tt class="docutils literal"><span class="pre">order_by</span></tt> keyword
argument to a table&#8217;s constructor.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.sequence">
<tt class="descname">sequence</tt><a class="headerlink" href="#Table.Meta.sequence" title="Permalink to this definition"></a></dt>
<dd><p>The sequence of the table columns. This allows the default order of
columns (the order they were defined in the Table) to be overridden.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body">any iterable (e.g. <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#tuple" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">tuple</span></tt></a> or <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#list" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">list</span></tt></a>)</td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><tt class="docutils literal"><span class="pre">()</span></tt></td>
</tr>
</tbody>
</table>
<p>The special item <tt class="docutils literal"><span class="pre">&quot;...&quot;</span></tt> can be used as a placeholder that will be
replaced with all the columns that weren&#8217;t explicitly listed. This
allows you to add columns to the front or back when using inheritence.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">first_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">... </span>    <span class="n">last_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
<span class="gp">... </span>        <span class="n">sequence</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;last_name&quot;</span><span class="p">,</span> <span class="s">&quot;...&quot;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Person</span><span class="o">.</span><span class="n">base_columns</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">[&#39;last_name&#39;, &#39;first_name&#39;]</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">&quot;...&quot;</span></tt> item can be used at most once in the sequence value. If
it&#8217;s not used, every column <em>must</em> be explicitly included. e.g. in the
above example, <tt class="docutils literal"><span class="pre">sequence</span> <span class="pre">=</span> <span class="pre">(&quot;last_name&quot;,</span> <span class="pre">)</span></tt> would be <strong>invalid</strong>
because neither <tt class="docutils literal"><span class="pre">&quot;...&quot;</span></tt> or <tt class="docutils literal"><span class="pre">&quot;first_name&quot;</span></tt> were included.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This functionality is also available via the <tt class="docutils literal"><span class="pre">sequence</span></tt> keyword
argument to a table&#8217;s constructor.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.orderable">
<tt class="descname">orderable</tt><a class="headerlink" href="#Table.Meta.orderable" title="Permalink to this definition"></a></dt>
<dd><p>Default value for column&#8217;s <em>orderable</em> attribute.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#True" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">True</span></tt></a></td>
</tr>
</tbody>
</table>
<p>If the table and column don&#8217;t specify a value, a column&#8217;s
<tt class="docutils literal"><span class="pre">orderable</span></tt> value will fallback to this. object specify. This
provides an easy mechanism to disable ordering on an entire table,
without adding <tt class="docutils literal"><span class="pre">orderable=False</span></tt> to each column in a table.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This functionality is also available via the <tt class="docutils literal"><span class="pre">orderable</span></tt> keyword
argument to a table&#8217;s constructor.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="Table.Meta.template">
<tt class="descname">template</tt><a class="headerlink" href="#Table.Meta.template" title="Permalink to this definition"></a></dt>
<dd><p>The default template to use when rendering the table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Default :</th><td class="field-body"><tt class="docutils literal"><span class="pre">&quot;django_tables2/table.html&quot;</span></tt></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This functionality is also available via the <em>template</em> keyword
argument to a table&#8217;s constructor.</p>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="booleancolumn">
<h3><a class="reference internal" href="#django_tables2.columns.BooleanColumn" title="django_tables2.columns.BooleanColumn"><tt class="xref py py-obj docutils literal"><span class="pre">BooleanColumn</span></tt></a><a class="headerlink" href="#booleancolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.BooleanColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">BooleanColumn</tt><big>(</big><em>null=False</em>, <em>yesno=u'u2714</em>, <em>u2718'</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#django_tables2.columns.BooleanColumn" title="Permalink to this definition"></a></dt>
<dd><p>A column suitable for rendering boolean data.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>null</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a>) &#8211; is <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a> different from <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#False" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">False</span></tt></a>?</li>
<li><strong>yesno</strong> (<em>iterable or string</em>) &#8211; text to display for True/False values, comma separated</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Rendered values are wrapped in a <tt class="docutils literal"><span class="pre">&lt;span&gt;</span></tt> to allow customisation by
themes. By default the span is given the class <tt class="docutils literal"><span class="pre">true</span></tt>, <tt class="docutils literal"><span class="pre">false</span></tt>.</p>
<p>In addition to <em>attrs</em> keys supported by <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a>, the following are
available:</p>
<ul class="simple">
<li><em>span</em> &#8211; adds attributes to the &lt;span&gt; tag</li>
</ul>
</dd></dl>

</div>
<div class="section" id="column">
<h3><a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a><a class="headerlink" href="#column" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.Column">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">Column</tt><big>(</big><em>verbose_name=None</em>, <em>accessor=None</em>, <em>default=None</em>, <em>visible=True</em>, <em>orderable=None</em>, <em>attrs=None</em>, <em>order_by=None</em>, <em>sortable=None</em>, <em>empty_values=None</em><big>)</big><a class="headerlink" href="#django_tables2.columns.Column" title="Permalink to this definition"></a></dt>
<dd><p>Represents a single column of a table.</p>
<p><a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> objects control the way a column (including the cells that
fall within it) are rendered.</p>
<dl class="attribute">
<dt id="Column.attrs">
<tt class="descname">attrs</tt><a class="headerlink" href="#Column.attrs" title="Permalink to this definition"></a></dt>
<dd><p>HTML attributes for elements that make up the column.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a></td>
</tr>
</tbody>
</table>
<p>This API is extended by subclasses to allow arbitrary HTML attributes
to be added to the output.</p>
<p>By default <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> supports:</p>
<ul class="simple">
<li><em>th</em> &#8211; <tt class="docutils literal"><span class="pre">table/thead/th</span></tt> elements</li>
<li><em>td</em> &#8211; <tt class="docutils literal"><span class="pre">table/tbody/tr/td</span></tt> elements</li>
<li><em>cell</em> &#8211; fallback if <em>th</em> or <em>td</em> isn&#8217;t defined</li>
</ul>
</dd></dl>

<dl class="attribute">
<dt id="Column.accessor">
<tt class="descname">accessor</tt><a class="headerlink" href="#Column.accessor" title="Permalink to this definition"></a></dt>
<dd><p>An accessor that describes how to extract values for this column from
the <a class="reference internal" href="#term-table-data"><em class="xref std std-term">table data</em></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#basestring" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">basestring</span></tt></a> or <a class="reference internal" href="#django_tables2.utils.Accessor" title="django_tables2.utils.Accessor"><tt class="xref py py-obj docutils literal"><span class="pre">Accessor</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Column.default">
<tt class="descname">default</tt><a class="headerlink" href="#Column.default" title="Permalink to this definition"></a></dt>
<dd><p>The default value for the column. This can be a value or a callable
object <a class="footnote-reference" href="#id11" id="id10">[1]</a>. If an object in the data provides <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#None" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">None</span></tt></a> for a column, the
default will be used instead.</p>
<p>The default value may affect ordering, depending on the type of data
the table is using. The only case where ordering is not affected is
when a <tt class="xref py py-obj docutils literal"><span class="pre">QuerySet</span></tt> is used as the table data (since sorting is
performed by the database).</p>
<table class="docutils footnote" frame="void" id="id11" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id10">[1]</a></td><td>The provided callable object must not expect to receive any
arguments.</td></tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Column.order_by">
<tt class="descname">order_by</tt><a class="headerlink" href="#Column.order_by" title="Permalink to this definition"></a></dt>
<dd><p>Allows one or more accessors to be used for ordering rather than
<em>accessor</em>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a>, <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#tuple" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">tuple</span></tt></a>, <a class="reference internal" href="#django_tables2.utils.Accessor" title="django_tables2.utils.Accessor"><tt class="xref py py-obj docutils literal"><span class="pre">Accessor</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Column.orderable">
<tt class="descname">orderable</tt><a class="headerlink" href="#Column.orderable" title="Permalink to this definition"></a></dt>
<dd><p>If <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#False" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">False</span></tt></a>, this column will not be allowed to influence row
ordering/sorting.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="Column.verbose_name">
<tt class="descname">verbose_name</tt><a class="headerlink" href="#Column.verbose_name" title="Permalink to this definition"></a></dt>
<dd><p>A human readable version of the column name.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a></td>
</tr>
</tbody>
</table>
<p>This should not defined in title case, but rather natural case. It is
converted to title case for use in column headers.</p>
</dd></dl>

<dl class="attribute">
<dt id="Column.visible">
<tt class="descname">visible</tt><a class="headerlink" href="#Column.visible" title="Permalink to this definition"></a></dt>
<dd><p>If <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#True" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">True</span></tt></a>, this column will be included in the HTML output.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Type :</th><td class="field-body"><a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a></td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="checkboxcolumn">
<h3><a class="reference internal" href="#django_tables2.columns.CheckBoxColumn" title="django_tables2.columns.CheckBoxColumn"><tt class="xref py py-obj docutils literal"><span class="pre">CheckBoxColumn</span></tt></a><a class="headerlink" href="#checkboxcolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.CheckBoxColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">CheckBoxColumn</tt><big>(</big><em>attrs=None</em>, <em>**extra</em><big>)</big><a class="headerlink" href="#django_tables2.columns.CheckBoxColumn" title="Permalink to this definition"></a></dt>
<dd><p>A subclass of <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> that renders as a checkbox form input.</p>
<p>This column allows a user to <em>select</em> a set of rows. The selection
information can then be used to apply some operation (e.g. &#8220;delete&#8221;) onto
the set of objects that correspond to the selected rows.</p>
<p>The value that is extracted from the <a class="reference internal" href="#term-table-data"><em class="xref std std-term">table data</em></a> for this column is
used as the value for the checkbox, i.e. <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;checkbox&quot;</span>
<span class="pre">value=&quot;...&quot;</span> <span class="pre">/&gt;</span></tt></p>
<p>This class implements some sensible defaults:</p>
<ul class="simple">
<li>HTML input&#8217;s <tt class="docutils literal"><span class="pre">name</span></tt> attribute is the <a class="reference internal" href="#term-column-name"><em class="xref std std-term">column name</em></a> (can override
via <em>attrs</em> argument).</li>
<li><em>orderable</em> defaults to <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/constants.html#False" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">False</span></tt></a>.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You&#8217;d expect that you could select multiple checkboxes in the rendered
table and then <em>do something</em> with that. This functionality isn&#8217;t
implemented. If you want something to actually happen, you&#8217;ll need to
implement that yourself.</p>
</div>
<p>In addition to <em>attrs</em> keys supported by <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a>, the following are
available:</p>
<ul class="simple">
<li><em>input</em>     &#8211; <tt class="docutils literal"><span class="pre">&lt;input&gt;</span></tt> elements in both <tt class="docutils literal"><span class="pre">&lt;td&gt;</span></tt> and <tt class="docutils literal"><span class="pre">&lt;th&gt;</span></tt>.</li>
<li><em>th__input</em> &#8211; Replaces <em>input</em> attrs in header cells.</li>
<li><em>td__input</em> &#8211; Replaces <em>input</em> attrs in body cells.</li>
</ul>
</dd></dl>

</div>
<div class="section" id="datecolumn">
<h3><a class="reference internal" href="#django_tables2.columns.DateColumn" title="django_tables2.columns.DateColumn"><tt class="xref py py-obj docutils literal"><span class="pre">DateColumn</span></tt></a><a class="headerlink" href="#datecolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.DateColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">DateColumn</tt><big>(</big><em>format=None</em>, <em>short=True</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#django_tables2.columns.DateColumn" title="Permalink to this definition"></a></dt>
<dd><p>A column that renders dates in the local timezone.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>format</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a>) &#8211; format string in same format as Django&#8217;s <tt class="docutils literal"><span class="pre">date</span></tt> template
filter (optional)</li>
<li><strong>short</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a>) &#8211; if <em>format</em> is not specified, use Django&#8217;s
<tt class="docutils literal"><span class="pre">SHORT_DATE_FORMAT</span></tt> setting, otherwise use <tt class="docutils literal"><span class="pre">DATE_FORMAT</span></tt></li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="datetimecolumn">
<h3><a class="reference internal" href="#django_tables2.columns.DateTimeColumn" title="django_tables2.columns.DateTimeColumn"><tt class="xref py py-obj docutils literal"><span class="pre">DateTimeColumn</span></tt></a><a class="headerlink" href="#datetimecolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.DateTimeColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">DateTimeColumn</tt><big>(</big><em>format=None</em>, <em>short=True</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#django_tables2.columns.DateTimeColumn" title="Permalink to this definition"></a></dt>
<dd><p>A column that renders datetimes in the local timezone.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>format</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a>) &#8211; format string for datetime (optional)</li>
<li><strong>short</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">bool</span></tt></a>) &#8211; if <em>format</em> is not specifid, use Django&#8217;s
<tt class="docutils literal"><span class="pre">SHORT_DATETIME_FORMAT</span></tt>, else <tt class="docutils literal"><span class="pre">DATETIME_FORMAT</span></tt></li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="emailcolumn">
<h3><a class="reference internal" href="#django_tables2.columns.EmailColumn" title="django_tables2.columns.EmailColumn"><tt class="xref py py-obj docutils literal"><span class="pre">EmailColumn</span></tt></a><a class="headerlink" href="#emailcolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.EmailColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">EmailColumn</tt><big>(</big><em>attrs=None</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#django_tables2.columns.EmailColumn" title="Permalink to this definition"></a></dt>
<dd><p>A subclass of <tt class="xref py py-obj docutils literal"><span class="pre">BaseLinkColumn</span></tt> that renders the cell value as a hyperlink.</p>
<p>It&#8217;s common to have a email value in a row hyperlinked to other page.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>attrs</strong> &#8211; a <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a> of HTML attributes that are added to
the rendered <tt class="docutils literal"><span class="pre">&lt;a</span> <span class="pre">href=&quot;...&quot;&gt;...&lt;/a&gt;</span></tt> tag</td>
</tr>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># models.py</span>
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
    <span class="n">email</span> <span class="o">=</span>  <span class="n">models</span><span class="o">.</span><span class="n">EmailField</span><span class="p">()</span>

<span class="c"># tables.py</span>
<span class="k">class</span> <span class="nc">PeopleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
    <span class="n">email</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">EmailColumn</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="filecolumn">
<h3><a class="reference internal" href="#django_tables2.columns.FileColumn" title="django_tables2.columns.FileColumn"><tt class="xref py py-obj docutils literal"><span class="pre">FileColumn</span></tt></a><a class="headerlink" href="#filecolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.FileColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">FileColumn</tt><big>(</big><em>verify_exists=True</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#django_tables2.columns.FileColumn" title="Permalink to this definition"></a></dt>
<dd><p>Attempts to render <tt class="xref py py-obj docutils literal"><span class="pre">FieldFile</span></tt> (or other storage backend <tt class="xref py py-obj docutils literal"><span class="pre">File</span></tt>) as a
hyperlink.</p>
<p>When the file is accessible via a URL, the file is rendered as a
hyperlink. The <tt class="xref py py-obj docutils literal"><span class="pre">basename</span></tt> is used as the text:</p>
<div class="highlight-python"><pre>&lt;a href="/media/path/to/receipt.pdf" title="path/to/receipt.pdf"&gt;receipt.pdf&lt;/a&gt;</pre>
</div>
<p>When unable to determine the URL, a <tt class="docutils literal"><span class="pre">span</span></tt> is used instead:</p>
<div class="highlight-python"><pre>&lt;span title="path/to/receipt.pdf"&gt;receipt.pdf&lt;/span&gt;</pre>
</div>
<p><a class="reference internal" href="#Column.attrs" title="Column.attrs"><tt class="xref py py-obj docutils literal"><span class="pre">Column.attrs</span></tt></a> keys <tt class="docutils literal"><span class="pre">a</span></tt> and <tt class="docutils literal"><span class="pre">span</span></tt> can be used to add additional attributes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>verify_exists</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#bool" title="(in Python v2.7)"><em>bool</em></a>) &#8211; attempt to determine if the file exists</td>
</tr>
</tbody>
</table>
<p>If <em>verify_exists</em>, the HTML class <tt class="docutils literal"><span class="pre">exists</span></tt> or <tt class="docutils literal"><span class="pre">missing</span></tt> is added to
the element to indicate the integrity of the storage.</p>
</dd></dl>

</div>
<div class="section" id="linkcolumn">
<h3><a class="reference internal" href="#django_tables2.columns.LinkColumn" title="django_tables2.columns.LinkColumn"><tt class="xref py py-obj docutils literal"><span class="pre">LinkColumn</span></tt></a><a class="headerlink" href="#linkcolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.LinkColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">LinkColumn</tt><big>(</big><em>viewname</em>, <em>urlconf=None</em>, <em>args=None</em>, <em>kwargs=None</em>, <em>current_app=None</em>, <em>attrs=None</em>, <em>**extra</em><big>)</big><a class="headerlink" href="#django_tables2.columns.LinkColumn" title="Permalink to this definition"></a></dt>
<dd><p>Renders a normal value as an internal hyperlink to another page.</p>
<p>It&#8217;s common to have the primary value in a row hyperlinked to the page
dedicated to that record.</p>
<p>The first arguments are identical to that of
<a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/urlresolvers.html#django.core.urlresolvers.reverse" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">reverse</span></tt></a> and allows an internal URL to be
described. The last argument <em>attrs</em> allows custom HTML attributes to
be added to the rendered <tt class="docutils literal"><span class="pre">&lt;a</span> <span class="pre">href=&quot;...&quot;&gt;</span></tt> tag.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>viewname</strong> &#8211; See <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/urlresolvers.html#django.core.urlresolvers.reverse" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">reverse</span></tt></a>.</li>
<li><strong>urlconf</strong> &#8211; See <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/urlresolvers.html#django.core.urlresolvers.reverse" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">reverse</span></tt></a>.</li>
<li><strong>args</strong> &#8211; See <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/urlresolvers.html#django.core.urlresolvers.reverse" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">reverse</span></tt></a>. **</li>
<li><strong>kwargs</strong> &#8211; See <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/urlresolvers.html#django.core.urlresolvers.reverse" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">reverse</span></tt></a>. **</li>
<li><strong>current_app</strong> &#8211; See <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/urlresolvers.html#django.core.urlresolvers.reverse" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">reverse</span></tt></a>.</li>
<li><strong>attrs</strong> &#8211; a <a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/stdtypes.html#dict" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">dict</span></tt></a> of HTML attributes that are added to
the rendered <tt class="docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;checkbox&quot;</span> <span class="pre">.../&gt;</span></tt> tag</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>** In order to create a link to a URL that relies on information in the
current row, <a class="reference internal" href="#django_tables2.utils.Accessor" title="django_tables2.utils.Accessor"><tt class="xref py py-obj docutils literal"><span class="pre">Accessor</span></tt></a> objects can be used in the <em>args</em> or
<em>kwargs</em> arguments. The accessor will be resolved using the row&#8217;s record
before <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/urlresolvers.html#django.core.urlresolvers.reverse" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">reverse</span></tt></a> is called.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># models.py</span>
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>

<span class="c"># urls.py</span>
<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="n">url</span><span class="p">(</span><span class="s">&#39;people/(\d+)/&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">people_detail</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;people_detail&#39;</span><span class="p">)</span>
<span class="p">)</span>

<span class="c"># tables.py</span>
<span class="kn">from</span> <span class="nn">django_tables2.utils</span> <span class="kn">import</span> <span class="n">A</span>  <span class="c"># alias for Accessor</span>

<span class="k">class</span> <span class="nc">PeopleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">LinkColumn</span><span class="p">(</span><span class="s">&#39;people_detail&#39;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="n">A</span><span class="p">(</span><span class="s">&#39;pk&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<p>In addition to <em>attrs</em> keys supported by <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a>, the following are
available:</p>
<ul class="simple">
<li><em>a</em> &#8211; <tt class="docutils literal"><span class="pre">&lt;a&gt;</span></tt> elements in <tt class="docutils literal"><span class="pre">&lt;td&gt;</span></tt>.</li>
</ul>
</dd></dl>

</div>
<div class="section" id="templatecolumn">
<h3><a class="reference internal" href="#django_tables2.columns.TemplateColumn" title="django_tables2.columns.TemplateColumn"><tt class="xref py py-obj docutils literal"><span class="pre">TemplateColumn</span></tt></a><a class="headerlink" href="#templatecolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.TemplateColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">TemplateColumn</tt><big>(</big><em>template_code=None</em>, <em>template_name=None</em>, <em>**extra</em><big>)</big><a class="headerlink" href="#django_tables2.columns.TemplateColumn" title="Permalink to this definition"></a></dt>
<dd><p>A subclass of <a class="reference internal" href="#django_tables2.columns.Column" title="django_tables2.columns.Column"><tt class="xref py py-obj docutils literal"><span class="pre">Column</span></tt></a> that renders some template code to use as
the cell value.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>template_code</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a>) &#8211; the template code to render</li>
<li><strong>template_name</strong> (<a class="reference external" href="/usr/share/doc/python2.7-doc/html/library/functions.html#unicode" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">unicode</span></tt></a>) &#8211; the name of the template to render</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>A <a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/templates/api.html#django.template.Template" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">Template</span></tt></a> object is created from the
<em>template_code</em> or <em>template_name</em> and rendered with a context containing:</p>
<ul class="simple">
<li><em>record</em> &#8211; data record for the current row</li>
<li><em>value</em> &#8211; value from <tt class="xref py py-obj docutils literal"><span class="pre">record</span></tt> that corresponds to the current column</li>
<li><em>default</em> &#8211; appropriate default value to use as fallback</li>
</ul>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ExampleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">foo</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">TemplateColumn</span><span class="p">(</span><span class="s">&#39;{{ record.bar }}&#39;</span><span class="p">)</span>
    <span class="c"># contents of `myapp/bar_column.html` is `{{ value }}`</span>
    <span class="n">bar</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">TemplateColumn</span><span class="p">(</span><span class="n">template_name</span><span class="o">=</span><span class="s">&#39;myapp/name2_column.html&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Both columns will have the same output.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">In order to use template tags or filters that require a
<a class="reference external" href="/usr/share/doc/python-django-doc/html/ref/templates/api.html#django.template.RequestContext" title="(in Django v1.5.4)"><tt class="xref py py-obj docutils literal"><span class="pre">RequestContext</span></tt></a>, the table <strong>must</strong> be rendered via
<a class="reference internal" href="#template-tags-render-table"><em>{% render_table %}</em></a>.</p>
</div>
</dd></dl>

</div>
<div class="section" id="urlcolumn">
<h3><a class="reference internal" href="#django_tables2.columns.URLColumn" title="django_tables2.columns.URLColumn"><tt class="xref py py-obj docutils literal"><span class="pre">URLColumn</span></tt></a><a class="headerlink" href="#urlcolumn" title="Permalink to this headline"></a></h3>
<dl class="class">
<dt id="django_tables2.columns.URLColumn">
<em class="property">class </em><tt class="descclassname">django_tables2.columns.</tt><tt class="descname">URLColumn</tt><big>(</big><em>attrs=None</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#django_tables2.columns.URLColumn" title="Permalink to this definition"></a></dt>
<dd><p>Renders URL values as hyperlinks.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">CompaniesTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">www</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">URLColumn</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span> <span class="o">=</span> <span class="n">CompaniesTable</span><span class="p">([{</span><span class="s">&quot;www&quot;</span><span class="p">:</span> <span class="s">&quot;http://google.com&quot;</span><span class="p">}])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">table</span><span class="o">.</span><span class="n">rows</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s">&quot;www&quot;</span><span class="p">]</span>
<span class="go">u&#39;&lt;a href=&quot;http://google.com&quot;&gt;http://google.com&lt;/a&gt;&#39;</span>
</pre></div>
</div>
<p>Additional attributes for the <tt class="docutils literal"><span class="pre">&lt;a&gt;</span></tt> tag can be specified via
<tt class="docutils literal"><span class="pre">attrs['a']</span></tt>.</p>
</dd></dl>

<p>See <a class="reference internal" href="internal.html"><em>Internal APIs</em></a> for internal classes.</p>
</div>
</div>
<div class="section" id="upgrading-from-django-tables-version-1">
<h2>Upgrading from django-tables Version 1<a class="headerlink" href="#upgrading-from-django-tables-version-1" title="Permalink to this headline"></a></h2>
<ul>
<li><p class="first">Change your <tt class="docutils literal"><span class="pre">INSTALLLED_APPS</span></tt> entry from <tt class="docutils literal"><span class="pre">&quot;django_tables.app&quot;</span></tt> to
<tt class="docutils literal"><span class="pre">&quot;django_tables2&quot;</span></tt>.</p>
</li>
<li><p class="first">Change all your import references from <tt class="docutils literal"><span class="pre">django_tables</span></tt> to
<tt class="docutils literal"><span class="pre">django_tables2</span></tt>.</p>
</li>
<li><p class="first">Replace all references to the old <tt class="docutils literal"><span class="pre">MemoryTable</span></tt> and <tt class="docutils literal"><span class="pre">ModelTable</span></tt>
classes with simply <tt class="docutils literal"><span class="pre">Table</span></tt>.</p>
</li>
<li><p class="first">In your templates, load the <tt class="docutils literal"><span class="pre">django_tables2</span></tt> template library;
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">django_tables2</span> <span class="pre">%}</span></tt> instead of <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">tables</span> <span class="pre">%}</span></tt>.</p>
</li>
<li><p class="first">A table object is no longer iterable; rather than <tt class="docutils literal"><span class="pre">for</span> <span class="pre">row</span> <span class="pre">in</span> <span class="pre">table</span></tt>,
instead you now do explicitly: <tt class="docutils literal"><span class="pre">for</span> <span class="pre">row</span> <span class="pre">in</span> <span class="pre">table.rows</span></tt>.</p>
</li>
<li><p class="first">If you were using <tt class="docutils literal"><span class="pre">row.data</span></tt> to access a row&#8217;s underlying data,
replace it with <tt class="docutils literal"><span class="pre">row.record</span></tt> instead.</p>
</li>
<li><p class="first">When declaring columns, replace the use of:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">name_in_dataset</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;wanted_column_name&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>with:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">wanted_column_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">accessor</span><span class="o">=</span><span class="s">&quot;name_in_dataset&quot;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">When declaring columns, replace the use of:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">column_to_override</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;wanted_column_name&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="s">&quot;name_in_dataset&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>with:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">wanted_column_name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">accessor</span><span class="o">=</span><span class="s">&quot;name_in_dataset&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>and exclude <tt class="docutils literal"><span class="pre">column_to_override</span></tt> via the table meta data.</p>
</li>
<li><p class="first">When generating the link to order the column, instead of:</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">set_url_param</span> <span class="nv">sort</span><span class="o">=</span><span class="nv">column.name_toggled</span> <span class="cp">%}</span><span class="x"></span>
</pre></div>
</div>
<p>use:</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">table.order_by_field</span><span class="o">=</span><span class="nv">column.order_by_alias.next</span> <span class="cp">%}</span><span class="x"></span>
</pre></div>
</div>
</li>
<li><p class="first">Replace:</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{{</span> <span class="nv">column.is_ordered_reverse</span> <span class="cp">}}</span><span class="x"> and </span><span class="cp">{{</span> <span class="nv">column.is_ordered_straight</span> <span class="cp">}}</span><span class="x"></span>
</pre></div>
</div>
<p>with:</p>
<div class="highlight-django"><div class="highlight"><pre><span class="cp">{{</span> <span class="nv">column.order_by.is_descending</span> <span class="cp">}}</span><span class="x"> and </span><span class="cp">{{</span> <span class="nv">column.order_by.is_ascending</span> <span class="cp">}}</span><span class="x"></span>
</pre></div>
</div>
</li>
</ul>
</div>
<div class="section" id="glossary">
<h2>Glossary<a class="headerlink" href="#glossary" title="Permalink to this headline"></a></h2>
<dl class="glossary docutils">
<dt id="term-accessor">accessor</dt>
<dd>Refers to an <a class="reference internal" href="#django_tables2.utils.Accessor" title="django_tables2.utils.Accessor"><tt class="xref py py-obj docutils literal"><span class="pre">Accessor</span></tt></a> object</dd>
<dt id="term-column-name">column name</dt>
<dd><p class="first">The name given to a column. In the follow example, the <em>column name</em> is
<tt class="docutils literal"><span class="pre">age</span></tt>.</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">SimpleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">age</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">()</span>
</pre></div>
</div>
</dd>
<dt id="term-empty-value">empty value</dt>
<dd>An empty value is synonymous with &#8220;no value&#8221;. Columns have an
<tt class="docutils literal"><span class="pre">empty_values</span></tt> attribute that contains values that are considered
empty. It&#8217;s a way to declare which values from the database correspond
to <em>null</em>/<em>blank</em>/<em>missing</em> etc.</dd>
<dt id="term-order-by-alias">order by alias</dt>
<dd><p class="first">A prefixed column name that describes how a column should impact the
order of data within the table. This allows the implementation of how
a column affects ordering to be abstracted, which is useful (e.g. in
querystrings).</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ExampleTable</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">Table</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">tables</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">order_by</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p class="last">In this example <tt class="docutils literal"><span class="pre">-name</span></tt> and <tt class="docutils literal"><span class="pre">name</span></tt> are valid order by aliases. In
a querystring you might then have <tt class="docutils literal"><span class="pre">?order=-name</span></tt>.</p>
</dd>
<dt id="term-table">table</dt>
<dd>The traditional concept of a table. i.e. a grid of rows and columns
containing data.</dd>
<dt id="term-view">view</dt>
<dd>A Django view.</dd>
<dt id="term-record">record</dt>
<dd>A single Python object used as the data for a single row.</dd>
<dt id="term-render">render</dt>
<dd>The act of serialising a <a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a> into
HTML.</dd>
<dt id="term-template">template</dt>
<dd>A Django template.</dd>
<dt id="term-table-data">table data</dt>
<dd>An interable of <a class="reference internal" href="#term-record"><em class="xref std std-term">records</em></a> that
<a class="reference internal" href="#django_tables2.tables.Table" title="django_tables2.tables.Table"><tt class="xref py py-obj docutils literal"><span class="pre">Table</span></tt></a> uses to populate its rows.</dd>
</dl>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="#">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">django-tables2 - An app for creating HTML tables</a><ul>
<li><a class="reference internal" href="#tutorial">Tutorial</a></li>
<li><a class="reference internal" href="#populating-a-table-with-data">Populating a table with data</a></li>
<li><a class="reference internal" href="#specifying-alternative-data-for-a-column">Specifying alternative data for a column</a></li>
<li><a class="reference internal" href="#specifying-alternative-ordering-for-a-column">Specifying alternative ordering for a column</a></li>
<li><a class="reference internal" href="#swapping-the-position-of-columns">Swapping the position of columns</a></li>
<li><a class="reference internal" href="#customising-column-headings">Customising column headings</a></li>
<li><a class="reference internal" href="#pagination">Pagination</a></li>
<li><a class="reference internal" href="#custom-rendering">Custom rendering</a><ul>
<li><a class="reference internal" href="#table-render-foo-methods"><tt class="docutils literal"><span class="pre">Table.render_FOO()</span></tt> methods</a></li>
<li><a class="reference internal" href="#subclassing-column">Subclassing <tt class="docutils literal"><span class="pre">Column</span></tt></a></li>
<li><a class="reference internal" href="#css">CSS</a></li>
<li><a class="reference internal" href="#custom-template">Custom Template</a></li>
</ul>
</li>
<li><a class="reference internal" href="#querystring-fields">Querystring fields</a></li>
<li><a class="reference internal" href="#column-attributes">Column attributes</a></li>
<li><a class="reference internal" href="#built-in-columns">Built-in columns</a></li>
<li><a class="reference internal" href="#template-tags">Template tags</a><ul>
<li><a class="reference internal" href="#render-table">render_table</a></li>
<li><a class="reference internal" href="#querystring">querystring</a></li>
</ul>
</li>
<li><a class="reference internal" href="#template-filters">Template filters</a><ul>
<li><a class="reference internal" href="#title">title</a></li>
</ul>
</li>
<li><a class="reference internal" href="#class-based-generic-mixins">Class Based Generic Mixins</a></li>
<li><a class="reference internal" href="#table-mixins">Table Mixins</a></li>
<li><a class="reference internal" href="#tables-for-models">Tables for models</a></li>
<li><a class="reference internal" href="#api-reference">API Reference</a><ul>
<li><a class="reference internal" href="#accessor-a"><tt class="docutils literal"><span class="pre">Accessor</span></tt> (<tt class="docutils literal"><span class="pre">A</span></tt>)</a></li>
<li><a class="reference internal" href="#requestconfig"><tt class="docutils literal"><span class="pre">RequestConfig</span></tt></a></li>
<li><a class="reference internal" href="#table"><tt class="docutils literal"><span class="pre">Table</span></tt></a></li>
<li><a class="reference internal" href="#table-meta"><tt class="docutils literal"><span class="pre">Table.Meta</span></tt></a></li>
<li><a class="reference internal" href="#booleancolumn"><tt class="docutils literal"><span class="pre">BooleanColumn</span></tt></a></li>
<li><a class="reference internal" href="#column"><tt class="docutils literal"><span class="pre">Column</span></tt></a></li>
<li><a class="reference internal" href="#checkboxcolumn"><tt class="docutils literal"><span class="pre">CheckBoxColumn</span></tt></a></li>
<li><a class="reference internal" href="#datecolumn"><tt class="docutils literal"><span class="pre">DateColumn</span></tt></a></li>
<li><a class="reference internal" href="#datetimecolumn"><tt class="docutils literal"><span class="pre">DateTimeColumn</span></tt></a></li>
<li><a class="reference internal" href="#emailcolumn"><tt class="docutils literal"><span class="pre">EmailColumn</span></tt></a></li>
<li><a class="reference internal" href="#filecolumn"><tt class="docutils literal"><span class="pre">FileColumn</span></tt></a></li>
<li><a class="reference internal" href="#linkcolumn"><tt class="docutils literal"><span class="pre">LinkColumn</span></tt></a></li>
<li><a class="reference internal" href="#templatecolumn"><tt class="docutils literal"><span class="pre">TemplateColumn</span></tt></a></li>
<li><a class="reference internal" href="#urlcolumn"><tt class="docutils literal"><span class="pre">URLColumn</span></tt></a></li>
</ul>
</li>
<li><a class="reference internal" href="#upgrading-from-django-tables-version-1">Upgrading from django-tables Version 1</a></li>
<li><a class="reference internal" href="#glossary">Glossary</a></li>
</ul>
</li>
</ul>

  <h4>Next topic</h4>
  <p class="topless"><a href="internal.html"
                        title="next chapter">Internal APIs</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/index.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="internal.html" title="Internal APIs"
             >next</a> |</li>
        <li><a href="#">django-tables2 0.13.0 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright .
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>