Django-cms: Get urls of many titles in one query, avoiding get_absolute_url()

Created on 23 Aug 2019  路  5Comments  路  Source: django-cms/django-cms

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 ?

Most helpful comment

Closing as this seems to have no actionables.

If you want to learn more about the work of the technical committee, our product vision and how you can become a member of the dCA, you can find all information here:

We are looking forward to every companion who would like to shape the future of django CMS together with us!

If you have any questions, feel free to reach out to Nicolai, our Community Manager: [email protected]

Sign up for the Association now!

All 5 comments

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.

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.

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

Closing as this seems to have no actionables.

If you want to learn more about the work of the technical committee, our product vision and how you can become a member of the dCA, you can find all information here:

We are looking forward to every companion who would like to shape the future of django CMS together with us!

If you have any questions, feel free to reach out to Nicolai, our Community Manager: [email protected]

Sign up for the Association now!

Fair enough. I don't think I'm going to get time to join the community association unless I get another role working on a djangocms project because I have too many projects already.

In case any one is, it would be good if DCMS:

  • Has a principle that any new database APIs should work in batch mode. (i.e., they are query objects that multiple items by default), this will enable composability.

Cheers for the info, and definitely may come back to this one day.

Was this page helpful?
0 / 5 - 0 ratings