Django-tables2:如何使用访问器引入外部列? [英] Django-tables2: How to use accessor to bring in foreign columns?

查看:105
本文介绍了Django-tables2:如何使用访问器引入外部列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试阅读此问题的文档和以前的答案没有多少运气。

I've tried reading the docs and previous answers to this question without much luck.

我有一堆学生课程注册,我想看到其中一些选定的注册与一些属性学生们。没有运气到目前为止...我会请求你的建议!

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!

这是模型:

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)

这里是tables.py:

and here is the tables.py:

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',)

当我收到有关出勤价值的数据时,学生外国栏目中没有任何内容。

While I'm getting data on the attendance values, there's nothing from the student foreign columns.

netID   First   Last    Attendance M    Attendance Tu
 —         —      —      ✔               ✘ 

如果我用model = Student启动Table,并使用注册表的访问者,这是一样的交易,这是一回事。

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.

我觉得我失踪了一些非常概念和关键的 - 请指导我!

I feel like I'm missing something very conceptual and crucial -- please guide me!

推荐答案

列的访问器参数中的模型名称应该是小写的。

The model name in the accessor parameter of the column should be lowercase.

使用 accessor ='student.netID'而不是 accessor ='Student.netID '

这篇关于Django-tables2:如何使用访问器引入外部列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆