Hi all, Thanks for all the feedback! I was expecting either a "do it like this" or a "sorry, it can't be done" type response - this is much better.
Tim - my initial solution was to use a differentiator view as you suggested. I thought this was a little messy because it dragged URL logic into my views, so I opened this thread to see if there was a better option. Before Emanuele's last comment I was also limited to not used generic views if I did it that way. Emanuele - you're totally right that it's a matter of opinion; sadly I'm working with an existing URL structure so I've got to do it this way. At least now I know I've surveyed all the options. Thanks again all, Matt. On Jul 30, 7:57 pm, Emanuele Pucciarelli <[EMAIL PROTECTED]> wrote: > Il giorno 30/lug/07, alle ore 17:21,Mattha scritto: > > > For instance, if you also had categories of users and wanted to be > > able to list the users in each category, a 'human-friendly' url > > scheme might look like this: > > >www.mysite.com/users/matt--> go to my area > >www.mysite.com/users/jess--> go to Jess' area > >www.mysite.com/users/mark--> go to Mark's area > >www.mysite.com/users/premium--> list all premium members > >www.mysite.com/users/economy--> list all economy members > > Whether that's more or less human-friendly is surely a matter of > opinion; for one, I wouldn't regard mixing users and user groups that > way as friendly - I'd find it misleading at best - but it's just an > opinion. Moreover, you should take care not to have objects of a > different kind with the same name. > > If you still wanted to do so *and* keep using generic views, you > could call them from a custom view. As an example, you could have in > your URL configuration a line like this: > > from yourapp.views import sorter > > [...] > > ( r'^users/(?P<slug>\w+)/$', sorter, {'slug_field': 'name',}, ), > > and in your views.py file: > > from django.core.exceptions import ObjectDoesNotExist > from django.http import Http404 > from django.views.generic.simple.list_detail import object_detail > from yourapp.models import User, Category > > def sorter(request, **kwargs): > for model in (Category, User, [...]): > try: > kwargs['queryset'] = model.objects.all() > return object_detail(request, **kwargs) > except ObjectDoesNotExist: > pass > return Http404 > > and this would let you map any object to the same URL scheme. But > first - is that really what you'd want? > > Regards, > > -- > Emanuele --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---