Hi,

> I have a class Photo and a class Category with a one to many
> relationship (many pictures can be in one category, but each photo can
> be in only one category)...
> I want to do an app for mysite/photo/category/OneCategory/ and have
> all picture in OneCategory... Nothing fancy.
> So far I managed to do it with mysite/photo/category/1 or 2 or n, n
> being the category.id but never with the actual name of the
> category...

First, setup your URL configuration regular expression to capture the
category name you need to match. That would be something like this:

(r'^photo/category/(?P<cat_name>[\w]+)/$', 'photos_by_category_view'),

That will call your view function photos_by_category_view with xyz
when you browse to the URL: /photo/category/xyz/

In your view function, you need a query set that will fetch all
relevant Photo objects. So, something like this would work there:

def photos_by_category_view(request, cat_name):
    photos = Photo.objects.filter(category__name=cat_name)
        # Send photos to your template, etc...

-Rajesh D

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

Reply via email to