diff --git a/README.rst b/README.rst index f7ae1a4a..4ca63937 100644 --- a/README.rst +++ b/README.rst @@ -977,6 +977,43 @@ which is inheriting any of the mixin classes. Usage example: `organization_field `_. +Django Filters Multi-tenant serializers for the browsable web UI +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Integration of `Django Filter `_ +with `Django REST Framework `_ +is provided through a DRF-specific FilterSet and a filter backend. + +The relationship fields in ``django-filters`` options interface shows all the +relationships, without filtering by the organization the user has access to, which +breaks multi-tenancy. + +The ``FilterDjangoByOrgMembership``, ``FilterDjangoByOrgManaged`` +and ``FilterDjangoByOrgOwned`` can be used to solve this issue. + +Usage example: + +.. code-block:: python + + from openwisp_users.api.mixins import FilterDjangoByOrgManaged + from ..models import FloorPlan + + + class FloorPlanOrganizationFilter(FilterDjangoByOrgManaged): + organization_slug = filters.CharFilter(field_name='organization__slug') + + class Meta: + model = FloorPlan + fields = ['organization', 'organization_slug'] + + + class FloorPlanListCreateView(ProtectedAPIMixin, generics.ListCreateAPIView): + serializer_class = FloorPlanSerializer + queryset = FloorPlan.objects.select_related().order_by('-created') + pagination_class = ListViewPagination + filter_backends = [filters.DjangoFilterBackend] + filterset_class = FloorPlanOrganizationFilter + Admin Multitenancy mixins -------------------------