Discussion:
Help with get absolute url
conrad22
2006-12-12 12:12:36 UTC
Permalink
Hi
Hopefully someone can step in here before I go totally mad...

I am trying to define the absolute_url and/or the urls.py file to
arrive at the following:

A list of categories, which leads to a list of organisations in each
category.
I want then each organisation in the list to go to its generic object
detail page.

At the moment, all I have defined for the get_absolute urls for both
categories and organisations
is the slug: nothing else.

The urls return as follows( all using generic views):

By category list:
http://127.0.0.1:8000/categories/
By category detail:
http://127.0.0.1:8000/categories/1/ (at the moment using the
object_id)
By organisation in category detail:
http://127.0.0.1:8000/categories/1/k/ (where I've used the
get_absolute_url method in the template, and 'k' is the organisation
slug).

Could someone please lend me a hand?
A billion thanks in advance.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
conrad22
2006-12-12 19:13:52 UTC
Permalink
Woops..see, I am already mad, as I have not communicated the actual
problem..!!!!

The last bit - 'categories/1/k/' returns a page/url not found error,
as follows:

Request Method: GET
Request URL: http://127.0.0.1:8000/categories/1/k/

Using the URLconf defined in kvn.urls, Django tried these URL patterns,
in this order:

1. ^$
2. ^kvn/$
3. ^kvn/(?P<object_id>\d+)/$
4. ^r/
5. kvn/add/$
6. ^admin/
7. ^feeds/(?P<url>.*)/$
8. ^categories/$
9. ^categories/(?P<object_id>\d+)/$

The current URL, /categories/1/k/, didn't match any of these.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Brett Parker
2006-12-12 19:19:25 UTC
Permalink
Post by conrad22
Woops..see, I am already mad, as I have not communicated the actual
problem..!!!!
The last bit - 'categories/1/k/' returns a page/url not found error,
Request Method: GET
Request URL: http://127.0.0.1:8000/categories/1/k/
Using the URLconf defined in kvn.urls, Django tried these URL patterns,
1. ^$
2. ^kvn/$
3. ^kvn/(?P<object_id>\d+)/$
4. ^r/
5. kvn/add/$
6. ^admin/
7. ^feeds/(?P<url>.*)/$
8. ^categories/$
9. ^categories/(?P<object_id>\d+)/$
The current URL, /categories/1/k/, didn't match any of these.
Errr, well it won't, the closest is 9... but you'd need something more
like:
^categories/(?P<object_id>\d+)/(?P<whatever_the_letter_is_for>\w+)/$

Cheers,
--
Brett Parker

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
conrad22
2006-12-13 08:48:43 UTC
Permalink
Yes, I know. Sorry, should have been more specific:
the problem is, that the second part of the url pattern comes from a
different model.

I've tried
(r'^categories/(?P<object_id>\d+)/(?P<organisation_slug>\w+)/$','django.views.generic.list_detail.object_detail',
info_dict),

but it's obviously not quite there...? How would I access the slugs
from the Organisation model within the Category models url patterns?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Waylan Limberg
2006-12-13 13:46:11 UTC
Permalink
Post by conrad22
the problem is, that the second part of the url pattern comes from a
different model.
I've tried
(r'^categories/(?P<object_id>\d+)/(?P<organisation_slug>\w+)/$','django.views.generic.list_detail.object_detail',
info_dict),
but it's obviously not quite there...? How would I access the slugs
from the Organisation model within the Category models url patterns?
You'll probably want to use a wrapper for your generic view. See:
http://www.b-list.org/weblog/2006/11/16/django-tips-get-most-out-generic-views
--
----
Waylan Limberg
***@gmail.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
conrad22
2006-12-13 18:49:11 UTC
Permalink
Mmm...I actually got it to work in the category_detail template:
{% for organisation in object.organisation_set.all %}
{{organisation.org_name}}
{% endfor %}

Each category does return a list of the organisations that are in it,
but what I need to do is then simply provide access to each
organisations generic detail view page (possibly using
get_absolute_url?)

You can see what I'm trying to do here:
http://www.ketteringcommunity.com/categories/

(ignore the styling!)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
conrad22
2006-12-14 10:37:31 UTC
Permalink
In other words, why can't I simply put

{{organisation.get_absolute_url}}

to return the organisation's detail page?

Surely the whole point of the get_absolute_url is to be able to call an
object from wherever?
So what would I put in the model and/or urls.py to be able to do this?
At the moment I just
have:

def get_absolute_url(self):
return self.slug

for the Organisation model.....?

Can't I just define this further?

With thanks in advance


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Waylan Limberg
2006-12-14 15:21:34 UTC
Permalink
This isn't working for you?

{% for organisation in object.organisation_set.all %}
<a href="{{ organisation.get_absolute_url }}">{{
organisation.org_name }}</a>
{% endfor %}

If the name works, but not get_absolute_url I'd say you have something
wrong with your model. Open a shell and play with you model to make
sure everything is working right.
--
----
Waylan Limberg
***@gmail.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
conrad22
2006-12-14 16:08:30 UTC
Permalink
You were quite right, Wayne, there was a mistake in my model (Charfield
instead of SlugField)...so don't I feel stupid!
A million thanks to everyone anyway!

(I feel quite well qualified to write an idiot's guide now...)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Loading...