On Sep 15, 5:56 pm, ChrisR <robthech...@gmail.com> wrote:
> Hello,
>
> I am building a blog/cms for my site.  I am using django's date_based
> urls as well as object_detail for the individual posts.
>
> On my base, I have a for loop for categories in the blog.  I don't
> like the way I have made the category_list work, and feel that it is
> not the best way to do it.  I would like some help with that if
> someone is willing to make suggestions.
>
> The category list appears on all pages within my blog, but when I do a
> search in the blog, the list disappears.
>
> Here are my views:
>
> from django.shortcuts import render_to_response, get_object_or_404
> from django.db.models import Q
> from blog.models import Category, Entry
>
> def category(request, slug):
>         category_list = Category.objects.all()
>         category = get_object_or_404(Category, slug=slug)
>         entry_list = Entry.objects.filter(category=category)
>         return render_to_response("blog/entry_list.html", locals())
>
> def search(request):
>         if 'q' in request.GET:
>                 term = request.GET['q']
>                 entry_list = Entry.objects.filter(Q(title__contains=term) | Q
> (html_content__contains=term))
>                 heading = "Search results"
>         return render_to_response("blog/entry_list.html", locals())
>
> Here are my urls:
>
> from django.conf.urls.defaults import *
> from blog.models import Entry, Category
>
> info_dict = {
>         'queryset' : Entry.objects.all(),
>         'date_field': 'created',
>         'template_object_name': 'entry',
>         "extra_context" : {"category_list" : Category.objects.all()}
>
> }
>
> urlpatterns = patterns('django.views.generic.date_based',
>         url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\w{1,2})/(?P<slug>[-
> \w]+)/$', 'object_detail', dict(info_dict, month_format='%m',
> slug_field='slug')),
>         url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\w{1,2})/$',
> 'archive_day', dict(info_dict, month_format='%m')),
>         url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$', 'archive_month', dict
> (info_dict, month_format='%m')),
>         url(r'^(?P<year>\d{4})/$', 'archive_year', info_dict),
>         url(r'^$', 'archive_index', info_dict),
> )
>
> urlpatterns += patterns('blog.views',
>         url(r'^category/(?P<slug>[-\w]+)/$', 'category', name="blog-
> category"),
>         url(r'^search/$', 'search', name="blog-search"),
> )
>
> If I need to provide more information let me know.  Thanks in advance!
>
> Chris

Things like category lists on every page are exactly what custom
template tags are for. You could include your tag on every template,
or even better on the base template that other templates inherit from,
and it will then definitely appear on every page.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to