use getattr on model_name because is new in django 1.6
fix code to respect pep8