【问题标题】:Filtering OrganizationUser's by Organization in Django-Organizations在 Django-Organizations 中按组织过滤组织用户
【发布时间】:2019-05-14 05:42:06
【问题描述】:

关于这个主题有一个相对相似的线程,但我似乎无法弄清楚如何将其转化为我的情况。我有一个名册,我只需要显示查看者的同一组织内的组织用户。我有一个正在开发的 web 应用程序,用于管理组织中的志愿者。我还是后端开发的新手,所以我无法解决问题。

这是使用 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 的新手,所以我不确定在这种情况下要解决什么问题。

【问题讨论】:

    标签: django python-3.x django-queryset modeling django-organizations


    【解决方案1】:

    试试:

    def get_queryset(self):
        return OrganizationUser.objects.filter(organization=self.request.user.organization)
    

    【讨论】:

    • 为什么在没有提供正确答案的情况下对他的评论投反对票..?
    猜你喜欢
    • 2018-07-28
    • 1970-01-01
    • 2019-11-20
    • 1970-01-01
    • 2013-03-28
    • 2012-04-22
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多