bradleyayers/django-tables2 — pull request #71 by selwin (2012-04-18 02:35:23+00:00)
Title: Add an option to provide a list of model fields for inclusion.

Hi there,

Currently, writing a table for a large model feels a little bit dirty to me. This code block is from the project I'm currently working on:

class ApplicationListTable(tables.Table):
class Meta:
model = Application
sequence = ('registration_number', 'user', 'comment_count', 'score_auto', 'score_manual', 'score', '...')
exclude = ('youtube', 'created', 'id', 'program', 'completed_count',
'form_completed_sections', 'submitted_date', 'scoring_status',
'status', 'modified', 'position')

I'd like to propose an option to specify a list of model fields for inclusion for ModelTables. The API is the same with Django's own [ModelForm ](https://docs.djangoproject.com/en/dev/topics/forms/modelforms/). With the proposed changes, the above code became:

class ApplicationListTable(tables.Table):

class Meta:
model = Application
fields = ('registration_number', 'user', 'comment_count',
'score_auto', 'score_manual', 'score',)
sequence = ('registration_number', 'user', 'comment_count',
'score_auto', 'score_manual', 'score', '...')

I haven't done any extensive testing on this (we can probably derive sequence from fields as well to make it even more elegant), but if you like the idea I'd be happy to provide tests and check for potential complications.

Let me know :)