Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[question] Authorization/Queryset filtering #1178

Unanswered
cocochepeau asked this question in Q&A
Discussion options

First of all, thanks for the amazing work!

By using this: http://docs.graphene-python.org/projects/django/en/latest/authorization/#queryset-filtering-on-lists
How can I achieve the same thing with relay queries. For example with:

class ProjectNode(DjangoObjectType):
 class Meta:
 model = Project
 interfaces = (relay.Node, )
class ProjectFilter(django_filters.FilterSet):
 class Meta:
 model = Project
 fields = [
 'id', 'published',
 ]
class Query(object):
 project = relay.Node.Field(ProjectNode)
 projects = DjangoFilterConnectionField(
 ProjectNode,
 filterset_class=ProjectFilter
 )
 def resolve_projects(self, args, info): # It does not work
 return Project.objects.filter(published=True)

Basically, I want to limit the queryset to only published projects.

Thanks again.

You must be logged in to vote

Replies: 3 comments

Comment options

I don't currently see a good way to do this, the querysets are merged during DjangoConnectionField.resolve_connection which grabs the default_queryset from the model's manager. I've had to extend my own DjangoFilterConnectionField to perform authorization checks. #79 purposes that the object nodes support a get_queryset method which would make this allot easier.

You must be logged in to vote
0 replies
Comment options

Thanks for your answer. I'm still learning Python/Django so thanks again for the explanation. :)
The idea would be to let us decide directly on the get_queryset method, like in https://docs.djangoproject.com/en/2.1/topics/db/managers/#modifying-a-manager-s-initial-queryset?

I'll try to follow #79 as well.

You must be logged in to vote
0 replies
Comment options

You would now define a ProjetNode.get_queryset to filter by user globally.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #490 on April 14, 2021 20:16.

AltStyle によって変換されたページ (->オリジナル) /