django/django — pull request #2705 by chris-morgan (2014-05-23 12:34:41+00:00)
Title: Special-case app_label detection from the shell.

People often seem to try to define model classes in the shell (for
better or for worse); at present this doesn't work without their also
defining app_label, leading to such comparatively popular questions as
http://stackoverflow.com/q/23757143. It is also a minor inconvenience
for experienced Django developers, because they must remember to set
app_label to a dummy value.

This takes care of that problem by assigning an app_label (a meaningless
value, of course) automatically, if the model class is in the `__main__`
module (which will close enough to always mean the shell—I don't want to
think about the alternative!).

There is no perfect solution to the problem—for this just delays the day
of judgment to another location, there being some things that you simply
can't reasonably do in the shell—but this fixes the minor papercut with
minimal side-effects.