【问题标题】:how to define a pk for models in django-tables 2 ? isn't it an automated?如何在 django-tables 2 中为模型定义 pk?不是自动的吗?
【发布时间】:2019-06-28 17:35:48
【问题描述】:

我使用 django-table2 来呈现用户输入的患者列表,但是由于未知原因,我收到了一个值错误: 解析访问器 Patient.pk 时,在 中查找键 [Patient] 失败

这是我的表.py

class PatientTable(tables.Table):

FirstName = tables.Column(linkify=("PatientDetailView", {"pk": tables.A("Patient.pk")}))
LastName = tables.Column(linkify=("PatientDetailView", {"pk": tables.A("Patient.pk")}))
Telephone_no = tables.Column(linkify=("PatientDetailView", {"pk": tables.A("Patient.pk")}))

class Meta:
    model = Patient
    # attrs = {'class': 'table table-striped table-hover'}
    exclude = ("user", "Notes", "Address")
    template_name = 'django_tables2/bootstrap4.html'

这是我在views.py中的视图函数

def Patients_list(request):
    table = PatientTable(Patient.objects.filter(user=request.user))

    return render(request, 'accounts/patients_list.html',{
    'table' : table
    })

【问题讨论】:

    标签: python django django-views django-tables2


    【解决方案1】:

    我变了:

    {"pk": tables.A("Patient.pk")}
    

    到:

    {"pk": tables.A("pk")}
    

    它成功了,我不知道我为什么要这样写。

    【讨论】:

      猜你喜欢
      • 2020-02-08
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 2020-08-22
      • 2014-04-05
      • 2011-12-05
      • 2019-01-14
      • 2012-07-06
      相关资源
      最近更新 更多