copied in changes from djangothis 0.7