Nov

23

Feed Me Seymour

In response to a flood of calls, telegrams and carrier pigeons, I have given in and implemented an Atom news feed for these posts. As a side effect, I've also implemented a blog post detail view.

Still to come: categories, comments, and pagination. For now, check out my date-based object_detail wrapper view.

def post_detail(request, year, month, day, slug):
return date_based.object_detail(
request,
year=year,
month=month, month_format="%B",
day=day,
slug=slug, slug_field='slug',
date_field='pub_date',
queryset=BlogPost.objects.all(),
template_object_name='blogpost'
)

At this point I could have just as easily used the generic view directly, but some of my fellow Django nerds have picked up two funny habits with views:

  1. Never use generic views directly
  2. Always use them indirectly.

That is, even if your view doesn't add anything you should still create it and call the generic view from inside instead of by using the generic view directly and passing a dict in the url conf. And even if your view does a whole bunch of stuff that's not at all covered by the generic view, you should still ultimately let some generic view generate the response. If nothing else, just use simple.direct_to_template and pass in your context.

The shortest explanation for why this makes sense is: we don't like business logic in our url confs, and we don't like having to construct RequestContext objects all the time. Beyond that, it's more hazy. To be honest, I'm still mostly giving it a test drive to see if my friends are crazy or not.