Thanks, Malcolm. That's basically what I was thinking. To clarify, though, I was saying a custom view for this would be quite simple - almost trivial - and I'm most assuredly *not* a programmer. I was only leaning toward a generic view because I trust them more than I do my own code.
Anyway, since the items know which category they're in, I'll just pass the category and item slugs to the view and query for the item that matches. Thanks! On Apr 2, 9:36 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2007-04-02 at 19:17 -0700, [EMAIL PROTECTED] wrote: > > I hope I explain this well. > > > I'm building a site that will have X number of categories. I don't > > know how many. > > Each category will have at least one item, but I don't know how many. > > > So, I need to display all categories, then each item in the category, > > then a detail view, without hardcoding the categories in urls.py > > (because more categories may be added at any time). > > > I can get as far as: > > (r'^(?P<slug>[-\w]+)/$', > > 'django.views.generic.list_detail.object_detail', dict(category_dict, > > slug_field='slug', template_name="category.html")), > > (r'^$', 'django.views.generic.list_detail.object_list', > > dict(queryset=Category.objects.all(), > > template_object_name="category", template_name="base.html")), > > > But for the detail view, I think I need something like /<cat_slug>/ > > <slug>/item > > > Can this be done in generic views, or do I need to write a custom > > view? I'm sure there's some bit of documentation somewhere I'm > > forgetting or havent' read that makes this easy > > The main problem -- and I think you are already hinting that you have > come across this -- is how to construct the queryset for the detail view > and for the "items in each category" view. It's not easy to do this in > the URL configuration file, because the queryset depends on parameters > in the URL. > > Instead, write a little view function that takes the parameters from the > URL and uses them to create the appropriate queryset. Then call the > generic view, passing in the right queryset. For an example of what I > mean, > seehttp://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-gen.... > > > (not that a custom > > view for this would be hard). > > As an aside: you need to disabuse yourself of this notion. :-) > > One of my genuine concerns with generic views is that people use them as > a crutch, rather than an aid, and struggle mightily against the urge to > move beyond their support. Writing full-blown view functions is not that > hard. Sure, you have to sit down and work out what information you want > and where to get it from, but it's just Python code. With generic views, > you have to learn a mini-language of which parameters to pass in and > what they mean and what your template will end up receiving. I suspect > people work through that and then think "well, normal views are going to > be even harder". They aren't. They're different and if you're used to > writing code, perhaps even easier. > > Regards, > Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---