def test_model_table():
 class OccupationTable(tables.Table, ):
  class Meta:
   model = Occupation
 expected = ['id', 'name', 'region', 'boolean', 'boolean_with_choices']
 assert (expected == list(OccupationTable.base_columns.keys()))
 class OccupationTable2(tables.Table, ):
  extra = tables.Column()
  class Meta:
   model = Occupation
 expected.append('extra')
 assert (expected == list(OccupationTable2.base_columns.keys()))
 from django.db import models
 class ComplexModel(models.Model, ):
  char = models.CharField(max_length=200)
  fk = models.ForeignKey('self', on_delete=models.CASCADE)
  m2m = models.ManyToManyField('self')
  class Meta:
   app_label = 'django_tables2_test'
 class ComplexTable(tables.Table, ):
  class Meta:
   model = ComplexModel
 assert (['id', 'char', 'fk'] == list(ComplexTable.base_columns.keys()))

def test_model_table ( ) : class OccupationTable ( tables . Table , ) : class Meta : model = Occupation expected = [ 'id' , 'name' , 'region' , 'boolean' , 'boolean_with_choices' ] assert ( expected == list ( OccupationTable . base_columns . keys ( ) ) ) class OccupationTable2 ( tables . Table , ) : extra = tables . Column ( ) class Meta : model = Occupation expected . append ( 'extra' ) assert ( expected == list ( OccupationTable2 . base_columns . keys ( ) ) ) from django . db import models class ComplexModel ( models . Model , ) : char = models . CharField ( max_length = 200 ) fk = models . ForeignKey ( 'self' , on_delete = models . CASCADE ) m2m = models . ManyToManyField ( 'self' ) class Meta : app_label = 'django_tables2_test' class ComplexTable ( tables . Table , ) : class Meta : model = ComplexModel assert ( [ 'id' , 'char' , 'fk' ] == list ( ComplexTable . base_columns . keys ( ) ) )
the model option on a table causes the table to dynamically add columns based on the fields .