question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Paginate list of records other than children

See original GitHub issue

If I want to have a page that lists all records in some complicated query, I can always write a custom model and template that directly makes that query, but this list can’t be paginated. I can also paginate the records from a complicated query with “child replacement”, by taking a model and redefining its children to be the result of that query, as documented in https://www.getlektor.com/docs/guides/categories/ . However, this replaces all the model’s old children, which it seems are no longer generated.

Example use case: I have a website that’s primarily a blog (a list of posts), but that also has some other subpages (e.g. an about page, category/tag pages). I want the root of my website to paginate the list of posts, but also for those other pages to be generated and linkable. Using child replacement on the root to replace the children with the list of blog posts, and then paginating that, doesn’t work because now the other pages are gone. Is this currently possible in Lektor?

If it doesn’t, one way I could imagine it working is to add a replaced_with field to the pagination section that replaces only the query used for pagination.entries. This seems somewhat inelegant as introducing two ways to do the same thing though. It’s also possible that child replacement preventing the old children from existing in the generated website isn’t intended/desirable behavior, but I haven’t really thought through the data model well enough to be sure about that.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
betaveroscommented, Sep 10, 2020

I think it’s used basically exactly like replaced_with, you specify a query of the list you want. So my blog’s front page’s data model has something like:

[pagination]
enabled = yes
per_page = 10
items = site.query('/post')

Analogously, to paginate the category pages in the category guide I think you could just as well replace

[children]
replaced_with = site.query('/projects').filter(F.categories.contains(this))

with

[pagination]
items = site.query('/projects').filter(F.categories.contains(this))
1reaction
betaveroscommented, Sep 10, 2020

So… I discovered in the code that pagination has a configuration option items that, as far as I can tell, literally does what the title of this issue says, implemented in 2015 in https://github.com/lektor/lektor/commit/f4448f54bd51c170c85b8660991b6fb7a047adcb and https://github.com/lektor/lektor/commit/31b3d9ce988411da8974b7109ab9c25015366938. And I guess it’s documented in https://www.getlektor.com/docs/models/children/, albeit in a way that doesn’t immediately suggest its applicability for this use case; it’s just not in the guides I looked at ¯\_(ツ)_/¯

Read more comments on GitHub >

github_iconTop Results From Across the Web

MS SQL Pagination Grouping By Parent while listing Children ...
Here's the scenario. I have a Newspaper and I want to list every issue of the newspaper and beneath the issue list all...
Read more >
jpa - How to get paginated child lists from OneToMany ...
I have done pagination for the child list (which does not know its parent) Query query = getEntityManager().createQuery( "select s.
Read more >
Paginating, sorting and filtering data from a Data Action
It's this subset that needs to be paginated and sorted, so both sorting and pagination need to be applied to the subset. To...
Read more >
The best database pagination technique is
Pagination is a strategy employed when querying any dataset that holds more than just a few hundred records. Thanks to pagination, we can ......
Read more >
Fast and Efficient Pagination in MongoDB | Codementor
MongoDB is a document based data store and hence pagination is one of the most common use case of it. Find out how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found