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.

get_absolute_url for topic and posts

See original GitHub issue

When I send notification to a poster and I would like to include a link to the post itself. However, there is no get_absolute_url defined for the Topic or Post models. Is there any reason they are not defined?

https://github.com/ellmetha/django-machina/blob/421b7da7d19087e143da5ab165e22ca43251bb28/machina/apps/forum_conversation/urls.py#L36-L41

looks like a good url for Topic, but there is no similar view_post url.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ellmethacommented, Feb 2, 2021

I really do not understand why get_absolute_url() was removed because it provides a natural Django way to refer to the forum, topic, or post without the long reverse(slug, pk, slug, pk) calls. Yes it means “presentation-related things in model”, it means server side rendering and might not work well with RESTful or SPA, but as a Django app it is natural to provide them and leave it to users on how to use them (and ABSOLUTE_URL_OVERRIDES is one way to override it).

Well, I think I explicitly stated in my previous message why it was removed: to improve separation of concern. 🙂 There is no need to debate whether or not having this method defined in models is a good or bad practice in general: I already stated that I was open to see it reintroduced.

0reactions
BoPengcommented, Feb 2, 2021

https://github.com/ellmetha/django-machina/commit/905f23a1f2a4eb64b282191778522fd83f9ca7d7 might not apply cleanly but all needed changes appear to be there.

I really do not understand why get_absolute_url() was removed because it provides a natural Django way to refer to the forum, topic, or post without the long reverse(slug, pk, slug, pk) calls. Yes it means “presentation-related things in model”, it means server side rendering and might not work well with RESTful or SPA, but as a Django app it is natural to provide them and leave it to users on how to use them (and ABSOLUTE_URL_OVERRIDES is one way to override it).

I have added these to my extended Topic class and might submit a PR when I get some time. Adding get_absolute_url is trivial but it takes more time to use it consistently throughout the project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django Quick Tips: get_absolute_url() - Level Up Coding
Create a basic Post model with two properties a title and content . models.py. Views. Then add basic view functions, one responsible for ......
Read more >
python - django get_absolute_url on search result
I am trying to insert link to each result so that the user can click a link to that post directly. I think...
Read more >
Try Django 1.9 - 19 of 38 - URL Links & Get Absolute URL
Subscribe to our channel: http://bit.ly/1kxmkzq Generally the topics will include: - Django Project Setup - Class Based Views (& some ...
Read more >
resource.getAbsoluteUrl() problem - SAP Community
#1.5#0012BF1423AB00450000028E0000144400043198E1852F02#1180432595640#com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl#sap.com/tcwddispwda#com.sap.
Read more >
get absolute url for the Image url - MSDN - Microsoft
Hi akpaga22,. Thanks for your post. I guess that your image path is a local file path and not a Url,so you cann't...
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