在这个主题上有一个相对类似的主题,但我似乎不知道如何将其转换为我的情况。我有一个花名册,我只需要显示查看器的同一组织内的组织和用户。我有一个我正在开发的webapp应用程序,用于管理组织中的志愿者。我仍然是后端开发的新手,所以我在解决问题时遇到了麻烦。
这是使用Django_Tables2包的表视图的代码:
#tables.py
class VolunteerTable(tables.Table):
class Meta:
model = OrganizationUser
# views.py
def VolunteerRoster(request):
table = tables.VolunteerTable(OrganizationUser.objects.all())
return render(request, 'staff/roster.html', {'table': table})
I'm trying to figure out how to either convert the view to a class-based view so I can use the OrganizationMixin and the SingleTableView in Django_Tables2's documentation.基于其他线程的解释,我正在考虑类似的事情。
class VolunteerRoster(SingleTableView, OrganizationMixin):
table_class = VolunteerTable
queryset = OrganizationUser.objects.all()
template_name = "staff_roster.html"
def get_queryset(self):
return self.queryset.filter(organization=self.get_organization())当我尝试这样做时,得到的结果是:"TypeError: init()接受1个位置参数,但给出了2个“
正如我所说的,我仍然是django的新手,所以我不确定在这个实例中要修复什么。
发布于 2018-12-13 13:21:32
尝试:
def get_queryset(self):
return OrganizationUser.objects.filter(organization=self.request.user.organization)https://stackoverflow.com/questions/53754533
复制相似问题