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

Custom manager is not working #351

Open
mirodil1 opened this issue Mar 19, 2024 · 0 comments
Open

Custom manager is not working #351

mirodil1 opened this issue Mar 19, 2024 · 0 comments

Comments

@mirodil1
Copy link

I've created new custom model manager, but when getting list of objects last added ones are not included, even if I clear cache after creating also not helped.
managers.py

from parler.managers import TranslatableManager

class PublishedManager(TranslatableManager):
    def get_queryset(self):
        return super().get_queryset().filter(news_status="published", publish__lte=timezone.now())

models.py

from .managers import PublishedManager

class News(TranslatableModel):
    ...
    objects = TranslatableManager()
    published = PublishedManager()

views.py

class NewsViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet):
    queryset = (
        News.published.prefetch_related(
            "translations"
        )
    )
    serializer_class = NewsSerializer
    def get_queryset(self) -> QuerySet:
        qs = super().get_queryset()
        language_code = get_language()
        return qs.filter(translations__language_code=language_code).order_by("-publish").distinct()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant