What are the benefits of the App-loading refactoring feature in the latest Django-1.7 release?

I read the docs but couldn't figure out how removing the need for models.py would improve the system.


source to share

1 answer

The benefits are listed as a bullet here . You can see that not demanding models.py

is just one of the stated benefits of the new approach.

  • Applications can run code on startup before Django does anything else by using the ready () method of their configuration.
  • Application shortcuts are assigned correctly to models, even if they are defined outside of models.py. You don't need to explicitly set app_label.
  • You can omit models.py entirely if your application doesn't have any models.
  • Applications can be relabeled with the label attribute for application configurations to work around label conflicts.
  • The application name can be configured in the administrator using the verbose_name of the application configurations.
  • The administrator automatically calls autodiscover () when Django starts. Hence, you can remove this line from the URLconf.
  • Django imports all application configurations and models as soon as it launches through a deterministic and simple process. This should make it easier to diagnose import problems such as import loops.

In addition, various errors related to application loading have been recorded under the rubric of application loading refactoring. For example, at one time some parts of the system looked INSTALLED_APPS

front-to-back and others back. The order is now consistent throughout the system.

As for models.py

, it doesn't make sense to use this to refer to applications when there is no need to have models for the application (for example, a reusable application can only have templates, say, or control commands), you had to include an empty models.py

file; you can now exclude it entirely.



All Articles