Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: auto_context_queryset_filter #50

Closed

Conversation

mbuvarp
Copy link
Collaborator

@mbuvarp mbuvarp commented Feb 21, 2021

I'm adding this as a draft PR for now just to get your input, cause perhaps you would go about it differently (if you want this meta option at all). That's also why I've only added it to update for now (and patch by extension, I guess). The tests work though.

I'll also add docs if and before this PR goes though.

@mbuvarp mbuvarp requested a review from tOgg1 February 21, 2021 19:26
Comment on lines +192 to +201
extend_query = False
query_extension = Q()
auto_context_queryset_filter = cls._meta.auto_context_queryset_filter or {}
for field_name, context_name in auto_context_queryset_filter.items():
if hasattr(info.context, context_name):
extend_query = True
query_extension &= Q(**{field_name: getattr(info.context, context_name)})

if extend_query:
queryset = queryset.filter(query_extension)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tOgg1 Should this thing perhaps be placed somewhere else?

@mbuvarp mbuvarp linked an issue Feb 21, 2021 that may be closed by this pull request
@mbuvarp mbuvarp added the enhancement New feature or request label Feb 21, 2021
@tOgg1
Copy link
Owner

tOgg1 commented Jan 15, 2024

Closing due to inactivity.

@tOgg1 tOgg1 closed this Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add auto_context_queryset_filter Meta field
2 participants