apps.get_model Application Registry in Django

apps.get_model(app_label, model_name, require_ready=True)

  • This Application Registry returns the Model with the given app_label and model_name. As a shortcut, this method also accepts a single argument in the form app_label.model_name.
  • model_name is case-insensitive.
  • Raises LookupError if no such application or model exists. 
  • Raises ValueError when called with a single argument that doesn’t contain exactly one dot.
  • Requires the app registry to be fully populated unless the require_ready argument is set to False.
  • Setting require_ready to False allows looking up models while the app registry is being populated, specifically during the second phase where it imports models. Then get_model() has the same effect as importing the model. 
  • The main use case is to configure model classes with settings, such as AUTH_USER_MODEL.
  • When require_ready is False, get_model() returns a model class that may not be fully functional until the app registry is fully populated. For this reason, it is best to leave require_ready to the default value of True whenever possible.

Comments

Popular posts from this blog

Internationalization (Language Setting) in Django

reverse_lazy() Method in Django

CharFilter in Django