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

Add pk_list projector and pair functions #29

Closed j4mie closed 3 years ago

j4mie commented 3 years ago

This adds a pair function pk_list which returns a flat list of the IDs of related objects:

spec = [
    "title",
    "publication_year",
    pk_list("author_set"),
]

results in..

{
    "title": "django-readers for dummies",
    "publication_year": "2021",
    "author_set": [1, 2, 3],
}