dabapps / django-readers

A lightweight function-oriented toolkit for better organisation of business logic and efficient selection and projection of data in Django projects.
https://www.django-readers.org
BSD 2-Clause "Simplified" License
186 stars 7 forks source link

How to retrieve the first child ? #73

Closed simkimsia closed 1 year ago

simkimsia commented 1 year ago
def get_fas_details_by_id(pk):
    """
    get fas by id for details
    """

    spec = [
        "id",
        "display",
        "fas_number",
        "fas_name",
        "pd_number",
        "wbs_level_1",
        "vc_number",
        "fas_type",
    ]

    prepare, project = specs.process(spec)
    product_package = prepare(ProjectStructureFas.objects.all()).get(pk=pk)

    return project(product_package)

I need to get the first child of ProjectStructureFas record.

How do I do this?

i know how to get all the children

def get_fas_details_by_id(pk):
    """
    get fas by id for details
    """
    spec_for_series = [
         pairs.filter(is_removed=False),
         pairs.order_by("display_order"),
         "id",
         "display",

    ]

    spec = [
        "id",
        "display",
        "fas_number",
        "fas_name",
        "pd_number",
        "wbs_level_1",
        "vc_number",
        "fas_type",
        {
             "series_set": spec_for_series
        },
    ]

    prepare, project = specs.process(spec)
    product_package = prepare(ProjectStructureFas.objects.all()).get(pk=pk)

    return project(product_package)

I like to get just the first child. How do I rewrite?

j4mie commented 1 year ago

See https://github.com/dabapps/django-readers/issues/58

simkimsia commented 1 year ago

oops. i forgot to reply. the original issue that initially prompted me to ask about first child.. it was no more. Because ended up I need to retrieve all children. 🤷🏻‍♂️

but i won't close this yet, until I confirm what's a good way to solve this generic issue of getting the first child using #58 as you suggested.

very thankful, @j4mie

Give me another 1 week. Sorry about this.

By the way, I just replaced a DRF serializer with django-readers... it's amazing. Just love, love it

j4mie commented 1 year ago

Going to close this now, we have the discussion in #58