GithubHelp home page GithubHelp logo

Comments (5)

rsinger86 avatar rsinger86 commented on May 4, 2024 1

Hi -- sorry about the delay in responding.

Here's an example below. It's a way to virtually segregate the database. For example, in a multi-tenant app, users of one tenant should have no awareness of another tenant's objects/rows. By having the scope_queryset method on the access policy class, the idea is to centralize the access logic.

ViewSet:

@property
    def access_policy(self):
        return self.permission_classes[0]

    def get_queryset(self):
        qs = self.access_policy.scope_queryset(self.request, Task.objects.all())

AccessPolicy:

    @classmethod
    def scope_queryset(cls, request, qs):
        return qs.filter(tenant_id=request.user.tenant_id, soft_delete=False)

from drf-access-policy.

hardntrash avatar hardntrash commented on May 4, 2024 1

ty, i will try. I think this isn't native solution and requires a description of this example in documentation. If possible, i will do it

from drf-access-policy.

rsinger86 avatar rsinger86 commented on May 4, 2024

Could you post the relevant parts of your code here?

from drf-access-policy.

hardntrash avatar hardntrash commented on May 4, 2024

изображение

Method scope_querset is unused and isn't called anywhere. How to use it? Maybe i should in ViewSet to assign queryset value from this method? Or, if possible, advise the correct use

from drf-access-policy.

puraminy avatar puraminy commented on May 4, 2024

what is self.request for ViewSets in the following code you posted? Do they have such property or it should be defined and assigned?


    def get_queryset(self):
        qs = self.access_policy.scope_queryset(self.request, Task.objects.all())

I get:

File "/home/ahmad/jkar/karmodir/views.py", line 47, in get_queryset
    self.request, self.queryset)
AttributeError: 'MemberViewSet' object has no attribute 'request'

from drf-access-policy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.