This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
Use default manager for all objects, separate manager - for published #86
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
👍 |
def get_query_set(self): | ||
qs = super(PublishedRelatedManager, self).get_query_set().filter( | ||
is_published=True) | ||
return qs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't agree with add one more manager to Article model just to filter published items. We must have a published method in manager and queryset, something like that:
from parler.managers import TranslatableManager, TranslatableQuerySet
class ArticleQuerySet(TranslatableQuerySet):
def published(self):
return self.filter(is_published=True)
class ArticleManager(TranslatableManager):
def get_queryset(self):
return ArticleQuerySet(self.model, using=self.db)
def published(self):
return self.get_query_set().published()
This way you can use published
anytime in a query, for example:
language = get_language_from_request(request, check_path=True)
events = Event.objects.language(language).translated(language)
if only_published:
events = events.published()
👍 , merge if travis say that is ok :) |
1 similar comment
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solves this issue: #74