Re: Permalink decorator and generic views, revisited

2007-03-13 Thread dchandek

> I *think* that so long as you don't have multiple URLs pointing at the
> same generic view you'll be OK, but otherwise there could be issues --
> we're working on it.

Thanks for the reply. This is exactly the problem. I want to use
object_detail and object_list for multiple URLs, so I'll be interested
to see what you come up with.

--David


--~--~-~--~~~---~--~~
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: Permalink decorator and generic views, revisited

2007-03-12 Thread James Bennett

On 3/12/07, dchandek <[EMAIL PROTECTED]> wrote:
> Am I missing something?

It's not that 'permalink' doesn't work with generic views -- it can.
As I understand it, the problem is a URLConf like this:

urlpatterns = patterns('django.views.generic.list_detail',
(r'^foo/(?P\d+)/$', 'object_detail', { 'queryset': Foo.objects.all() }),
(r'^bar/(?P\d+)/$', 'object_detail', { 'queryset': Bar.objects.all() }),
)

The 'get_absolute_url' methods for the 'Foo' and 'Bar' models will
probably be identical:

def get_absolute_url(self):
return ('django.views.generic.list_detail.object_detail', (), {
'id': str(self.id) })
get_absolute_url = permalink(get_absolute_url)

And this is where we get into trouble: we've got two distinct URL
patterns which point to the same view with the same argument signature
(django.views.generic.list_detail.object_detail(id=self.id)). As far
as I know, we currently only return the first matching URL, so in this
case 'get_absolute_url' for both 'Foo' and 'Bar' will return a
'/foo//' URL, because that's the first one it finds that matches.

I *think* that so long as you don't have multiple URLs pointing at the
same generic view you'll be OK, but otherwise there could be issues --
we're working on it.

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Permalink decorator and generic views, revisited

2007-03-12 Thread dchandek

I posted previously about how it seemed to me that, while the
permalink decorator is useful in decoupling the get_absolute_url()
methods of an application's models from the site/project, it more or
less forces you to create dummy custom views where you would normally
simply use generic views. Here's what I find myself doing repeatedly:

In models.py:

from django.db.models import permalink
import views

class Item(models.Model):
...
def get_absolute_url(self):
return (views.item_detail, (str(self.id),))
get_absolute_url = permalink(get_absolute_url)


In urls.py (included in project URLconf):

from django.conf.urls.defaults import *
from views import *

urlpatterns = patterns('',
(r'^item/(?P\d+)/$', item_detail),
)


In views.py:

from django.views.generic.list_detail import object_detail,
object_list
import models

def item_detail(request, object_id=None):
return object_detail(request, queryset=models.Item.objects.all(),
object_id=object_id)


Am I missing something?

Thanks,
David


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---