Django code refactorization