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

Simplify posts property on Category model #105

Open
stuartmaxwell opened this issue Jan 23, 2025 · 0 comments
Open

Simplify posts property on Category model #105

stuartmaxwell opened this issue Jan 23, 2025 · 0 comments
Assignees
Labels
refactor Refactor existing code

Comments

@stuartmaxwell
Copy link
Owner

The following code in category.py, line 116:

    @property
    def posts(self) -> models.QuerySet:
        """Return only published posts."""
        return self._posts.filter(
            status="published",
            date__lte=timezone.now(),
        )

Can be changed to:

    @property
    def posts(self) -> models.QuerySet:
        """Return only published posts."""
        return self._posts

Or, I may be able to remove this and rename the related model to posts instead of _posts. I only called it _posts because I wanted to add some extra logic to the posts property. But this logic (only returning published posts) is now built into the default queryset of the manager.

@stuartmaxwell stuartmaxwell self-assigned this Jan 23, 2025
@stuartmaxwell stuartmaxwell added the refactor Refactor existing code label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor existing code
Projects
Status: No status
Development

No branches or pull requests

1 participant