Re: trying to understand get_absolute_url, NoReverseMatch and url configs

2008-10-27 Thread bobhaugen

Some followup, in case some other poor soul searches for this topic:

I found some better doc for get-absolute-url() here:

http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#get-absolute-url

Including a better example:

@models.permalink
def get_absolute_url(self):
return ('archive_view', (), {
'year': self.created.year,
'month': self.created.month,
'day': self.created.day})

So I changed my method like this:

@models.permalink
def get_absolute_url(self):
return ('organization', (), {
"type_slug": self.type.slug,
"org_slug": self.slug})

...which works!

However, the permalink decorator still doesn't work.  Get error:
AttributeError: 'Org' object has no attribute 'permalink'
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trying to understand get_absolute_url, NoReverseMatch and url configs

2008-10-27 Thread bobhaugen

Got the url tag version working this way:

Changed the url pattern to:

url(r'^org/(?P[-\w]+)/(?P[-\w]+)/$',
'orgs.views.org', name='organization'),

And the template to:

{% url organization type_slug=org.type.slug, org_slug=org.slug %}

And added the new keyword to the view.

But I'm still a long ways from understanding this stuff enuf to do a
new one with any confidence.

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



Re: trying to understand get_absolute_url, NoReverseMatch and url configs

2008-10-27 Thread bobhaugen

Tried going about this another way:
In the template:

{% url orgs.views.org org.type.slug, org_slug=org.slug %}

That gets me this error message:

Don't mix *args and **kwargs in call to reverse()!

But how is that different from this example in the Django doc?

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

{% url path.to.some_view arg1,arg2,name1=value1 %}

"The first argument is a path to a view function in the format
package.package.module.function. Additional arguments are optional and
should be comma-separated values that will be used as positional and
keyword arguments in the URL. All arguments required by the URLconf
should be present."
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trying to understand get_absolute_url, NoReverseMatch and url configs

2008-10-27 Thread bobhaugen

Shabda,

Thanks for trying, but:

>  return ('orgs.views.org', [self.type.slug, self.slug])

In the shell, that gets me:
TypeError: reverse() argument after ** must be a dictionary

But do I understand correctly that the first argument shd be a view?

And that what gets returned from get_absolute_url goes into reverse()?
Looking at the code for urlresolvers.revers() now.  If I read
correctly, it wants either a view or an URL pattern name.

That's a start at getting more understanding.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trying to understand get_absolute_url, NoReverseMatch and url configs

2008-10-27 Thread shabda

You want something like this

@models.permalink
def get_absolute_url(self):
 return ('orgs.views.org', [self.type.slug, self.slug])

Essentially, you code would be doing something like reverse('/org/
hoa/', kwargs={..}) which fails. Templates supress Exceptions so you
do not see them.


On Oct 27, 9:48 pm, bobhaugen <[EMAIL PROTECTED]> wrote:
> Altho I have read alot of the relevant documentation, and searched
> this group and the Web, I remain confused about these topics and their
> relationships.  Something is not sticking in my brain.
>
> I usually get something working by blind cut and paste.  Looking for a
> more conceptual explanation, or even some pointers to where to look
> next.
>
> Here's my current problem:
>
> in models.py:
>
>     def get_absolute_url(self):
>         prefix = "/org/%s/" % self.type.slug
>         return (prefix, None, {"org_slug": iri_to_uri(self.slug)})
>
> in urls.py:
>
>     url(r'^org/(\w)+/(?P[-\w]+)/$', 'orgs.views.org',
> name='org'),
>
> in a template:
>
>     {{ org.get_absolute_url }}
>
> returns nothing.  No error message.
>
> Error message from the shell:
>
> >>>org,get_absolute_url()
>
> [...]
> NoReverseMatch: Reverse for '/org/hoa/' with arguments '()' and
> keyword arguments '{'org_slug': 'cp'}' not found.
>
> If I enter the urlhttp://127.0.0.1:8000/org/hoa/cp/in the address
> bar, it works fine.
>
> Using current trunk and the Django dev server.
>
> What am I missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



trying to understand get_absolute_url, NoReverseMatch and url configs

2008-10-27 Thread bobhaugen

Altho I have read alot of the relevant documentation, and searched
this group and the Web, I remain confused about these topics and their
relationships.  Something is not sticking in my brain.

I usually get something working by blind cut and paste.  Looking for a
more conceptual explanation, or even some pointers to where to look
next.

Here's my current problem:

in models.py:

def get_absolute_url(self):
prefix = "/org/%s/" % self.type.slug
return (prefix, None, {"org_slug": iri_to_uri(self.slug)})

in urls.py:

url(r'^org/(\w)+/(?P[-\w]+)/$', 'orgs.views.org',
name='org'),

in a template:

{{ org.get_absolute_url }}

returns nothing.  No error message.

Error message from the shell:

>>>org,get_absolute_url()
[...]
NoReverseMatch: Reverse for '/org/hoa/' with arguments '()' and
keyword arguments '{'org_slug': 'cp'}' not found.

If I enter the url http://127.0.0.1:8000/org/hoa/cp/ in the address
bar, it works fine.

Using current trunk and the Django dev server.

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