diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-27 23:03:03 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-28 09:34:46 +0100 |
| commit | aff57793b46e108c6e48d5ce3b889bf90b513df9 (patch) | |
| tree | 337ea34de977d56b2ca40eb4dd4c3d46d4671b93 /django/core/management/commands/sqlsequencereset.py | |
| parent | 3518e9ec1f23f0278aefea6738f9d49eb7d4fe52 (diff) | |
Simplified the implementation of register_model.
register_model is called exactly once in the entire Django code base, at the
bottom of ModelBase.__new__:
new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
ModelBase.__new__ exits prematurely 120 lines earlier (sigh) if a model with
the same name is already registered:
if new_class._meta.apps.get_registered_model(new_class._meta.app_label, name):
return
(This isn't the exact code, but it's equivalent.)
apps.register_model and apps.get_registered_model are essentially a setter and
a getter for apps.all_models, and apps.register_model is the only setter. As a
consequence, new_class._meta.apps.all_models cannot change in-between.
Considering that name == new_class.__name__, we can conclude that
register_model(app_label, model) is always called with such arguments that
get_registered_model(app_label, model.__name__) returns None.
Considering that model._meta.model_name == model.__name__.lower(), and looking
at the implementation of register_model and get_registered_model, this proves
that self.all_models[app_label] doesn't contain model._meta.model_name in
register_model, allowing us to simplify the implementation.
Diffstat (limited to 'django/core/management/commands/sqlsequencereset.py')
0 files changed, 0 insertions, 0 deletions
