Filtering OrganizationUser's by Organization in Django-Organizations

384 Views Asked by At

There is a relatively similar thread on this topic, but I can't seem to figure out how to translate it to my situation. I have a roster that I need to only display the organizationusers within the same organization of the viewer. I have a webapp that I am developing that is used to manage volunteers in an organization. I'm still new to backend development so I'm having trouble problem solving.

This is the code for the table view using Django_Tables2 package:

#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.

I was thinking about something like this based on the other threads explanation

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())

When I try this I get: "TypeError: init() takes 1 positional argument but 2 were given"

As I said, I'm still new to django so I'm not really sure what to fix in this instance.

1

There are 1 best solutions below

1
On

Try:

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