gpt4 book ai didi

python - Django-tables2:如何使用访问器引入外部列?

转载 作者:太空狗 更新时间:2023-10-29 21:37:28 25 4
gpt4 key购买 nike

我已经尝试阅读文档和以前的 answers这个问题运气不好。

我有一堆学生类(class)注册,我想查看其中一些选定的注册以及学生的一些属性。到目前为止运气不好……我想征求你的意见!

这是模型:

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:

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

虽然我正在获取有关出勤值的数据,但学生外国专栏中没有任何数据。

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

如果我以 model = Student 启动表并针对注册表使用访问器,结果是一样的。

我觉得我缺少一些非常概念性和关键性的东西——请指导我!

最佳答案

列的访问器参数中的型号名称应为小写。

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

关于python - Django-tables2:如何使用访问器引入外部列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20777125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com