reorganize and extend django related code