I need to write the following querysets mixins:
class VendorOwnedQuerySetMixin(models.QuerySet):
def get_objects_for_vendor(self, request):
vendor_user = VendorUserModel.objects.get(user=request.user)
return qs.filter(vendor=vendor_user.vendor)
class OrganizationOwnedQuerySetMixin(object):
def get_objects_for_organization(self, request):
return self.filter(organization__domains__name=hostname_from_request(request))
All's working well because some model managers will inherit the first mixin and some inherit the second.
Then inside the get_queryset
of the viewset, i will call the appropriate get_objects method.
example
def get_queryset(self, queryset=None):
return Some.objects.get_objects_for_organization(self.request)
Now I need to have a django rest viewset that needs to run the get_queryset
method that runs both filters.
How do I "chain" them within the get_queryset
method? Because I want to reuse my code where possible