Living on the Edge

Django Gets Intermediate Models

Posted on July 29, 2008

With Changeset 8136 Django gains the ability to specify intermediate models in a declarative way. This makes it possible to have extra attributes on your many-to-many join table. Check out the docs for more information.

I’ve been watching this one for almost a very long time and I’m glad to see it get in. Special thanks go to Eric Florenzano and Russell Keith-Magee

This Week in Django 24 - 2008-06-01

Posted on June 02, 2008

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

This week Eric Florenzano fills in while Michael is out. We talk to James Tauber about who he is and what Pinax is. A few trunk changes and some community bits.

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

Downloads

AAC Enhanced Podcast (32.7 MB, 44:47, AAC)

MP3 Edition (41.7 MB, 44:47, MP3)

OGG Edition (53.7 MB, 44:47, Vorbis)

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

Quick note, Brian Rosner did the audio in Michael’s absence. Its not as good as what Michael produces, but he is getting better with it :)

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 __at__ thisweekindjango.com.

Show Notes

Big News (0:25)

We’re back! Apologizes for last week’s cancellation. Michael’s wife gave birth to their 2nd child, Lucas Matthew Trier. Welcome to the world, Lucas!

James Tauber Interview (1:12)

  • James is the CTO at US-based startup mValent.
    • Tell us a little about mValent? Is Django involved?
  • How did you come to find and use Django?

Tracking Trunk (31:51)

Community Catchup (35:09)

  • sleepy-django – Sleepy, allows you to create a static site by rendering Django templates to HTML.

Thank You! (39:08)

  • Special thanks to Brian Rosner for handling the show production this week. You did an awesome job man.

This Week in Django 21 - 2008-05-04

Posted on May 06, 2008

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 __at__ 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<tag>\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<tag>\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<year>\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/(?P<author_id>d+)/$', 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)

   # Record the last accessed date
   author.last_accessed = datetime.datetime.now()
   author.save()

   # 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)