this code can work with django 1.5 and later