Django Tables2 Display Multiple Tables
<p>I've got user records that have related(ish) course and enrollment records.  I want to click on a user and see raw data from the user table, course table, and enrollment table in the same page.</p>

<p>The process breaks down when I attempt to render the tables.</p>

<p>views.py:</p>

<pre><code>def explore_related(request, client_id, user_id):
    client = get_object_or_404(Client, pk=client_id)

    users = Users.objects.filter(pk=user_id)

    enrollments = Enrollments.objects.filter(client_id=client_id).filter(userID__in=users.values_list('userID', flat=True)).all()

    courses = Courses.objects.filter(client_id=client_id).filter(sectionSchoolCode__in=enrollments.values_list('sectionSchoolCode', flat=True)).all()

    userTable = UserTable(users, prefix='u_')

    courseTable = CourseTable(courses, prefix='c_')

    enrollmentTable = EnrollmentTable(enrollments, prefix='e_')

    payload = {
        'userTable': userTable,
        'enrollmentTable': enrollmentTable,
        'courseTable': courseTable,
    }

    return render(request, 'importer/explore_related.html', payload)
</code></pre>

<p>explore_related.html:</p>

<pre><code>{% load render_table from django_tables2 %}
&lt;html&gt;
    &lt;body&gt;
        {% render_table userTable %}
        &lt;br&gt;
        {% render_table courseTable %}
        &lt;br&gt;
        {% render_table enrollmentTable %}
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>tables.py</p>

<pre><code>class UserTable(tables.Table):
    selection = tables.CheckBoxColumn(accessor='userID', orderable=False)
    errors = tables.Column()
    User_ID = tables.LinkColumn(
        'importer:explore_related',
        text=lambda record: record.userID,
        kwargs={
            'client_id': tables.A('client_id'),
            'file_kind': 'user',
            'object_id': tables.A('id'),
        },
        empty_values='NULL',

    )

    class Meta:
        model = Users
        attrs = {'class': 'paleblue'}
        exclude = ['id', 'client', 'userID']

        sequence = (
            'selection',
            '...',
            'errors'
        )


class CourseTable(tables.Table):
    selection = tables.CheckBoxColumn(accessor='pk', orderable=False)
    errors = tables.Column()

    class Meta:
        model = Courses
        attrs = {'class': 'paleblue'}
        exclude = ['id', 'client']

        sequence = (
            'selection',
            '...',
            'errors'
        )


class EnrollmentTable(tables.Table):
    selection = tables.CheckBoxColumn(accessor='pk', orderable=False)
    errors = tables.Column()

    class Meta:
        model = Enrollments
        attrs = {'class': 'paleblue'}
        exclude = ['id', 'client']

        sequence = (
            'selection',
            '...',
            'errors'
        )
</code></pre>

<p>If you use custom table classes, you need to use a <strong>RequestConfig</strong> object to properly set-up the table.</p>

<p>In your example, it should be enough to add</p>

<pre><code>RequestConfig(request, paginate=False).configure(userTable)
RequestConfig(request, paginate=False).configure(courseTable)
RequestConfig(request, paginate=False).configure(enrollmentTable)
</code></pre>

<p>before adding them to <em>payload</em>.</p>

python django django-tables2