Skip to content

Query categories recursively #366

@Yelinz

Description

@Yelinz

How should the category filter on the documents traverse the child categories to return all documents from parent and children.
Currently it will only do one layer of children

I think if we need to query categories recursively, we should either use something like MPTT, or cache the parents of each category in an ArrayField. Recursively iterating in a query is a bad idea performance-wise.
Since we didn't have positive-only experience with MPTT, I would suggest adding a all_parents = ArrayField(CharField()) to the category model, add a bit of code to keep them updated, and the query basically becomes all_parents__contains=my_category_slug

Originally posted by @winged in #365 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions