我是Django表的新手,但我的模型看起来像这样:
class EmployeeResponse(models.Model):
user = models.ForeignKey(User)
employee = models.ForeignKey(Employee)
question = models.CharField(max_length=200, blank=True, null=True)
我想使用django_tables2
填充员工响应数据,我为此创建了一个如下所示的表:
class EmployeeResponseTable(tables.Table):
user = tables.Column(orderable=True)
employee = tables.Column(orderable=True)
question = tables.Column(orderable=False)
class Meta:
model = EmployeeResponse
exclude = ['id']
sequence = ("user","employee", "question")
一切正常,但用户和员工专栏没有进行排序。请帮我解决这个问题。此外,我正在填充用户和员工数据,如
data =[]
employee_responses = EmployeeResponse.objects.all()
for er in employee_responses:
data.append({"user": er.user, "employee": er.employee, "question": er.question})
然后使用
推送所有数据table = EmployeeResponseTable(data)
我不知道为什么不进行排序。请求帮助我。
答案 0 :(得分:0)
您需要一个RequestConfig
对象。
from django_tables2 import RequestConfig
table = EmployeeResponseTable(data)
RequestConfig(request).configure(table)