Il giorno 30/lug/07, alle ore 17:21, Matt ha 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---