Skip to content
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

Get urls of many titles in one query, avoiding get_absolute_url() #6722

Open
stuaxo opened this issue Aug 23, 2019 · 3 comments

Comments

@stuaxo
Copy link

commented Aug 23, 2019

Using title.get_absolute_url() is not ideal, as it can't be incorporated into a query that gets many titles.

Given a query that returns a lot of tags, is there a way I can grab the urls from all of them, by doing something that runs purely in a queryset ?

@benzkji

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

as get_absolute_url() needs to check various things, this probably wont work. for example, it must check:

  • am I a homepage, ie "/"?
  • have I an "override_url" set
  • get alle the slugs of the parent pages, construct slug

as far as I can judge, this will not work on a db level only.

@stuaxo

This comment has been minimized.

Copy link
Author

commented Sep 5, 2019

It seems like the database + API are not setup easily for batch access.

The first two seem like they might be doable in a queryset.

The last one seems more difficult, I'm not quite sure what the database structure is here, or how the slug is constructed.

@benzkji

This comment has been minimized.

Copy link
Contributor

commented Sep 5, 2019

the slug is constructed like this:

/parent-slug/parent-slug/..../current-item-slug/

it is a tree, based on django-treebeard. short story: the tree structure is in its own table, having assigned a draft/public version the Page, and each of these has a Title for every language configured.

dig into it: https://github.com/divio/django-cms/blob/develop/cms/models/pagemodel.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.