Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango-tables2: How to use accessor to bring in foreign columns?
    text
    copied!<p>I've tried reading the docs and previous <a href="https://stackoverflow.com/questions/14461480/accessing-related-models-with-django-tables2">answers</a> to this question without much luck.</p> <p>I've got a bunch of student-course registrations and I'd like to see some of those selected registrations in conjunction with some of the attributes of the students. No luck so far...I'd request your advice!</p> <p>Here's the model:</p> <pre><code>class Student(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) netID = models.CharField(max_length=8) class Registration(models.Model): student = models.ForeignKey(Student) course = models.ForeignKey(Course) attendance_M = models.BooleanField(default=False) attendance_Tu = models.BooleanField(default=False) </code></pre> <p>and here is the tables.py:</p> <pre><code>class AttendanceTable(tables.Table): netID = tables.Column(accessor='Student.netID') first = tables.Column(accessor='Student.first_name') last = tables.Column(accessor='Student.last_name') class Meta: model = Registration attrs = {"class": "paleblue"} fields = ('attendance_M', 'attendance_Tu',) sequence = ('netID', 'first', 'last', 'attendance_M', 'attendance_Tu',) </code></pre> <p>While I'm getting data on the attendance values, there's nothing from the student foreign columns.</p> <pre><code>netID First Last Attendance M Attendance Tu — — — ✔ ✘ </code></pre> <p>And it's the same deal if I start the Table with model = Student and use accessors against the Registration table, it's the same deal.</p> <p>I feel like I'm missing something very conceptual and crucial -- please guide me!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload