Skip to content

♻️(documents) inherit manager from queryset #797

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

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

qbey
Copy link
Member

@qbey qbey commented Mar 24, 2025

Purpose

During a code review, I saw we are overriding the MP_NodeManager and redefine the queryset filters:

  • The MP_NodeManager sorts the queryset by path by default and it's not done on our side, is it on purpose?
  • The fact we need to redefine readable_per_se as a boilerplate is surprising.

Proposal

I suggest we use the Django mechanism to generate the manager from the queryset.

  • Use the from_queryset class method to generate the document manager.

@qbey qbey requested a review from lunika March 24, 2025 11:26
@qbey qbey self-assigned this Mar 24, 2025
@qbey qbey added the backend label Mar 24, 2025
"""
return self.get_queryset().readable_per_se(user)
"""Sets the custom queryset as the default."""
return self._queryset_class(self.model).order_by('path')
Copy link
Member Author

Choose a reason for hiding this comment

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

See

class MP_NodeManager(models.Manager):
    """Custom manager for nodes in a Materialized Path tree."""

    def get_queryset(self):
        """Sets the custom queryset as the default."""
        return MP_NodeQuerySet(self.model).order_by('path')

@qbey qbey force-pushed the qbey/document-manager-simple branch from dedbb5e to b866bb7 Compare March 24, 2025 11:29
@lunika
Copy link
Member

lunika commented Mar 24, 2025

I suggest to inherit from MP_NodeManager directly as suggested in their documentation. Also in the library they inherit from the manager like we are doing : https://github.com/django-treebeard/django-treebeard/blob/master/treebeard/mp_tree.py#L133

If it's ok to mix the "django way" and what they made, I agree to merge this PR.

During a code review, I saw we are overriding the MP_NodeManager and
redefine the queryset filters:

- The MP_NodeManager sorts the queryset by `path` by default and it's
  not done on our side, is it on purpose?
- The fact we need to redefine `readable_per_se` as a boilerplate is
  surprising.

I suggest we use the Django mechanism to generate the manager from the
queryset.
@lunika lunika force-pushed the qbey/document-manager-simple branch from b866bb7 to 27aa7c4 Compare March 24, 2025 13:52
@lunika lunika enabled auto-merge (rebase) March 24, 2025 13:52
@lunika lunika merged commit 2929e98 into main Mar 24, 2025
17 of 19 checks passed
@lunika lunika deleted the qbey/document-manager-simple branch March 24, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants