Tuesday, May 6, 2008

This Week in Django 21

with hosts Michael Trier and Brian Rosner

Bookmark and Share

This Week in Django is a weekly podcast about all things Django.

This week we have a couple of special guests. First, Eric Florenzano joins us for most of the show, and provides special insight into a few conversation items. Secondly we privileged to have Francis Cleary on the program to discuss a couple Tip of the Week items. We also cover all the regular stuff plus stream the program live on ustream.

Please see the Show Notes below for all the pertinent information and links

Downloads

AAC Enhanced Podcast (33.2 MB, 1:01:14, AAC)

MP3 Edition (42.1 MB, 1:01:14, MP3)

OGG Edition (31.9 MB, 1:01:14, Vorbis)

The Enhanced Podcast version contains screenshots and easy access links to all of the items we discuss throughout the podcast.

Feeds Available

iTunes Feeds are available. By subscribing using the iTunes feeds the podcasts will automatically be downloaded for you when we release them.

iTunes Feeds

This Week in Django – AAC Edition

This Week in Django – MP3 Edition

Regular RSS Feeds

This Week in Django – AAC Edition

This Week in Django – MP3 Edition

This Week in Django – OGG Edition

Give Us Feedback

Want to give us some feedback on the show? We’re always looking for ideas or suggestions that will help improve each episode. Please contact us at feedback <i>at</i> thisweekindjango.com.

Show Notes

Tracking Trunk (2:50)

Branching & Merging (8:53)

Community Catchup (19:38)

  • Django l10n – Marc Garcia, who was on last week’s show provides a followup post that does a great job of pulling together the information we discussed as well as stuff we did not get time to cover.

Tip of the Week (36:16)

Francis Cleary is on the show with us this week to present his tip that he entered in the Win Cool Stuff Contest and was our grand prize winner.

Multiple view prefixes

Rather then have complex and long urls like so


urlpatterns += patterns('',
   (r'^$', 'mySite.Project.views.mainpage' ),
   (r'^custom/view/$', 'mySite.Project.views.'view_function'),
   (r'^lookup/tag/(?P\w+)/$', 'mySite.Project.views.tag_list'),
   (r'^users/$' , 'django.views.generic.list_detail.object_list', user_dict),
   (r'^recent/$','django.views.generic.list_detail.object_list', all_dict),
   (r^text/$', 'django.views.generic.date_based.object_detail', object_dict),
)

Take advantage of the first argument to the patterns() function to specify a prefix to apply to each view function. just make sure you have the += not just =.


urlpatterns += patterns('mySite.Project.views',
   (r'^$', 'mainpage'),
   (r'^custom/view/$', 'view_function'),
   (r'^lookup/tag/(?P\w+)/$', 'tag_list'),
)

urlpatterns += patterns(‘django.views.generic’,
(r’^users/$’ , ‘list_detail.object_list’, user_dict),
(r’^recent/$’, ‘list_detail.object_list’, all_dict),
(r’^(?P\d{4})/$’, ‘date_based.archive_year’, object_dict),
)

Advanced Generic Views

If you don’t want your urls.py filling up with dictionary or would like to do more complicated filtering or extra work to a list. Define view functions that return your generic view and dictionary.

In this example from the Django Book. We will use a generic view to
display an author but we want to update the last_accessed data.


urls.py

from mysite.books.views import author_detail

urlpatterns = patterns(’’,
#...
(r’^authors/(?Pd+)/$’, author_detail),
)


views.py

import datetime
from mysite.books.models import Author
from django.views.generic import list_detail
from django.shortcuts import get_object_or_404

def author_detail(request, author_id):
# Look up the Author (and raise a 404 if she’s not found)
author = get_object_or_404(Author, pk=author_id)

  1. Record the last accessed date
    author.last_accessed = datetime.datetime.now()
    author.save()
  1. Show the detail page
    return list_detail.object_detail(
    request,
    queryset = Author.objects.all(),
    object_id = author_id,
    )

Rather then calling the generic view from the urls.py you can once
again see how uncoupled things are in django and just return the
generic view from your own wrapped view.

  • Are you generic? – Great earlier post by Wilson Miner on using Generic Views for non-programmers.

IRC Ad Nauseam (45:33)

Django IRC FAQ

Backwards Incompatible Changes Information

  • We have discussed the changes to the Paginator that occured during the PyCon 2008 sprints, but we are still seeing people tripping up over it. Paginator originally worked only on QuerySets, but has now been abstracted out. Paginiator is now generalized enough to work on lists. This is the reason for QuerySetPaginator. It special cases certain things to prevent performing the wrong operation on the QuerySet.

>>> from cameras.models import CameraImage
>>> CameraImage.objects.all().count()
248788L
>>> from django.core.paginator import Paginator 
>>> paginator = Paginator( CameraImage.objects.all(), 48, True)
>>> import time;start=time.time(); page = paginator.page(50); print time.time()-start
17.4773068428

Some questions about general IRC

We get lots of questions about IRC in general, so maybe a few little tidbits here and there:

Why don’t you use manners? When I say Thank You, you don’t respond.

Okay here’s the deal, there’s no reason to increase the noise level on IRC. That means although we appreciate the thanks, often we will not acknowledge it. So don’t take it personally.

I asked a question and no one responded. Why is that?

People will answer if they know. You can re-ask but please wait a bit. Don’t use the #django-dev channel, that’s the wrong thing to do.

It might be good to think about how you can rephrase the question.

Use the Django-Users Mailing list. It’s another avenue available.

Can anyone help with a NewForms-Admin Question?

Don’t ask to ask. Just ask straight away. It depends often on the area of the question. So it’s best to just ask your question.

Will “blank” work?

Try it. Often the best thing to do is try it. That’s what anyone will end up doing.

Couple other tips, read the FAQ, Backwards Incompatible Changes, and the Freenode FAQ.

Thank You! (58:20)

Comments - 2 people have already said something. Join the discussion.

  • Raisins said

    Awesome show, Glad I came on.

  • Greg Fuller said

    Thanks, guys. And after listing to the IRC discussion, I don't expect a 'you're welcome' :)