From ec469ade2b04b94bfeb59fb0fc7d9300470be615 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Tue, 5 Feb 2013 04:16:07 -0500 Subject: [PATCH] Fixed #19689 -- Renamed `Model._meta.module_name` to `model_name`. --- django/contrib/admin/actions.py | 2 +- django/contrib/admin/options.py | 24 +++++++-------- django/contrib/admin/sites.py | 6 ++-- .../admin/auth/user/change_password.html | 2 +- .../admin/templates/admin/change_form.html | 2 +- .../contrib/admin/templatetags/admin_urls.py | 3 +- django/contrib/admin/util.py | 2 +- django/contrib/admin/views/main.py | 2 +- django/contrib/admin/widgets.py | 4 +-- django/contrib/admindocs/views.py | 12 ++++---- django/contrib/auth/context_processors.py | 16 +++++----- django/contrib/auth/management/__init__.py | 2 +- django/contrib/comments/moderation.py | 4 +-- django/contrib/comments/views/comments.py | 4 +-- django/contrib/contenttypes/generic.py | 4 +-- django/contrib/contenttypes/management.py | 2 +- django/contrib/contenttypes/models.py | 10 +++---- django/contrib/gis/sitemaps/kml.py | 2 +- django/core/cache/backends/db.py | 2 +- django/core/management/sql.py | 4 +-- django/core/serializers/python.py | 2 +- django/core/xheaders.py | 2 +- django/db/models/base.py | 4 +-- django/db/models/fields/related.py | 8 ++--- django/db/models/loading.py | 2 +- django/db/models/options.py | 29 +++++++++++++------ django/db/models/related.py | 10 +++---- django/views/generic/detail.py | 6 ++-- django/views/generic/list.py | 4 +-- docs/internals/deprecation.txt | 2 ++ docs/releases/1.6.txt | 6 ++++ .../admin_custom_urls/models.py | 2 +- 32 files changed, 102 insertions(+), 84 deletions(-) diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py index 201101736e..d11ba3d1a8 100644 --- a/django/contrib/admin/actions.py +++ b/django/contrib/admin/actions.py @@ -75,7 +75,7 @@ def delete_selected(modeladmin, request, queryset): # Display the confirmation page return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [ - "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.object_name.lower()), + "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.model_name), "admin/%s/delete_selected_confirmation.html" % app_label, "admin/delete_selected_confirmation.html" ], context, current_app=modeladmin.admin_site.name) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 8e0aaccc86..8de31121e0 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -371,7 +371,7 @@ class ModelAdmin(BaseModelAdmin): return self.admin_site.admin_view(view)(*args, **kwargs) return update_wrapper(wrapper, view) - info = self.model._meta.app_label, self.model._meta.module_name + info = self.model._meta.app_label, self.model._meta.model_name urlpatterns = patterns('', url(r'^$', @@ -783,7 +783,7 @@ class ModelAdmin(BaseModelAdmin): form_template = self.change_form_template return TemplateResponse(request, form_template or [ - "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), + "admin/%s/%s/change_form.html" % (app_label, opts.model_name), "admin/%s/change_form.html" % app_label, "admin/change_form.html" ], context, current_app=self.admin_site.name) @@ -803,7 +803,7 @@ class ModelAdmin(BaseModelAdmin): self.message_user(request, msg) if post_url_continue is None: post_url_continue = reverse('admin:%s_%s_change' % - (opts.app_label, opts.module_name), + (opts.app_label, opts.model_name), args=(pk_value,), current_app=self.admin_site.name) if "_popup" in request.POST: @@ -845,14 +845,14 @@ class ModelAdmin(BaseModelAdmin): msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict self.message_user(request, msg) return HttpResponseRedirect(reverse('admin:%s_%s_change' % - (opts.app_label, opts.module_name), + (opts.app_label, opts.model_name), args=(pk_value,), current_app=self.admin_site.name)) elif "_addanother" in request.POST: msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict self.message_user(request, msg) return HttpResponseRedirect(reverse('admin:%s_%s_add' % - (opts.app_label, opts.module_name), + (opts.app_label, opts.model_name), current_app=self.admin_site.name)) else: msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict @@ -867,7 +867,7 @@ class ModelAdmin(BaseModelAdmin): opts = self.model._meta if self.has_change_permission(request, None): post_url = reverse('admin:%s_%s_changelist' % - (opts.app_label, opts.module_name), + (opts.app_label, opts.model_name), current_app=self.admin_site.name) else: post_url = reverse('admin:index', @@ -882,7 +882,7 @@ class ModelAdmin(BaseModelAdmin): opts = self.model._meta if self.has_change_permission(request, None): post_url = reverse('admin:%s_%s_changelist' % - (opts.app_label, opts.module_name), + (opts.app_label, opts.model_name), current_app=self.admin_site.name) else: post_url = reverse('admin:index', @@ -1060,7 +1060,7 @@ class ModelAdmin(BaseModelAdmin): if request.method == 'POST' and "_saveasnew" in request.POST: return self.add_view(request, form_url=reverse('admin:%s_%s_add' % - (opts.app_label, opts.module_name), + (opts.app_label, opts.model_name), current_app=self.admin_site.name)) ModelForm = self.get_form(request, obj) @@ -1283,7 +1283,7 @@ class ModelAdmin(BaseModelAdmin): context.update(extra_context or {}) return TemplateResponse(request, self.change_list_template or [ - 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), + 'admin/%s/%s/change_list.html' % (app_label, opts.model_name), 'admin/%s/change_list.html' % app_label, 'admin/change_list.html' ], context, current_app=self.admin_site.name) @@ -1323,7 +1323,7 @@ class ModelAdmin(BaseModelAdmin): return HttpResponseRedirect(reverse('admin:index', current_app=self.admin_site.name)) return HttpResponseRedirect(reverse('admin:%s_%s_changelist' % - (opts.app_label, opts.module_name), + (opts.app_label, opts.model_name), current_app=self.admin_site.name)) object_name = force_text(opts.verbose_name) @@ -1346,7 +1346,7 @@ class ModelAdmin(BaseModelAdmin): context.update(extra_context or {}) return TemplateResponse(request, self.delete_confirmation_template or [ - "admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()), + "admin/%s/%s/delete_confirmation.html" % (app_label, opts.model_name), "admin/%s/delete_confirmation.html" % app_label, "admin/delete_confirmation.html" ], context, current_app=self.admin_site.name) @@ -1373,7 +1373,7 @@ class ModelAdmin(BaseModelAdmin): } context.update(extra_context or {}) return TemplateResponse(request, self.object_history_template or [ - "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()), + "admin/%s/%s/object_history.html" % (app_label, opts.model_name), "admin/%s/object_history.html" % app_label, "admin/object_history.html" ], context, current_app=self.admin_site.name) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 185417015a..07d1ec7804 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -247,7 +247,7 @@ class AdminSite(object): # Add in each model's views. for model, model_admin in six.iteritems(self._registry): urlpatterns += patterns('', - url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name), + url(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), include(model_admin.urls)) ) return urlpatterns @@ -351,7 +351,7 @@ class AdminSite(object): # Check whether user has any perm for this module. # If so, add the module to the model_list. if True in perms.values(): - info = (app_label, model._meta.module_name) + info = (app_label, model._meta.model_name) model_dict = { 'name': capfirst(model._meta.verbose_name_plural), 'object_name': model._meta.object_name, @@ -407,7 +407,7 @@ class AdminSite(object): # Check whether user has any perm for this module. # If so, add the module to the model_list. if True in perms.values(): - info = (app_label, model._meta.module_name) + info = (app_label, model._meta.model_name) model_dict = { 'name': capfirst(model._meta.verbose_name_plural), 'object_name': model._meta.object_name, diff --git a/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/contrib/admin/templates/admin/auth/user/change_password.html index 83a9c48ee1..9d1b917b61 100644 --- a/django/contrib/admin/templates/admin/auth/user/change_password.html +++ b/django/contrib/admin/templates/admin/auth/user/change_password.html @@ -19,7 +19,7 @@ {% endblock %} {% endif %} {% block content %}
-
{% csrf_token %}{% block form_top %}{% endblock %} +{% csrf_token %}{% block form_top %}{% endblock %}
{% if is_popup %}{% endif %} {% if form.errors %} diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index 48846960b3..daf37753dc 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -35,7 +35,7 @@ {% endif %}{% endif %} {% endblock %} -{% csrf_token %}{% block form_top %}{% endblock %} +{% csrf_token %}{% block form_top %}{% endblock %}
{% if is_popup %}{% endif %} {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} diff --git a/django/contrib/admin/templatetags/admin_urls.py b/django/contrib/admin/templatetags/admin_urls.py index 90e81b0ef3..bca95d92ae 100644 --- a/django/contrib/admin/templatetags/admin_urls.py +++ b/django/contrib/admin/templatetags/admin_urls.py @@ -1,4 +1,3 @@ -from django.core.urlresolvers import reverse from django import template from django.contrib.admin.util import quote @@ -6,7 +5,7 @@ register = template.Library() @register.filter def admin_urlname(value, arg): - return 'admin:%s_%s_%s' % (value.app_label, value.module_name, arg) + return 'admin:%s_%s_%s' % (value.app_label, value.model_name, arg) @register.filter diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py index 07013d1d4b..133a8ad13e 100644 --- a/django/contrib/admin/util.py +++ b/django/contrib/admin/util.py @@ -116,7 +116,7 @@ def get_deleted_objects(objs, opts, user, admin_site, using): admin_url = reverse('%s:%s_%s_change' % (admin_site.name, opts.app_label, - opts.object_name.lower()), + opts.model_name), None, (quote(obj._get_pk_val()),)) p = '%s.%s' % (opts.app_label, opts.get_delete_permission()) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index be7067ff61..4b296b3f4f 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -379,6 +379,6 @@ class ChangeList(object): def url_for_result(self, result): pk = getattr(result, self.pk_attname) return reverse('admin:%s_%s_change' % (self.opts.app_label, - self.opts.module_name), + self.opts.model_name), args=(quote(pk),), current_app=self.model_admin.admin_site.name) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index a3887740d8..4b79401dbc 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -147,7 +147,7 @@ class ForeignKeyRawIdWidget(forms.TextInput): # The related object is registered with the same AdminSite related_url = reverse('admin:%s_%s_changelist' % (rel_to._meta.app_label, - rel_to._meta.module_name), + rel_to._meta.model_name), current_app=self.admin_site.name) params = self.url_parameters() @@ -247,7 +247,7 @@ class RelatedFieldWidgetWrapper(forms.Widget): def render(self, name, value, *args, **kwargs): rel_to = self.rel.to - info = (rel_to._meta.app_label, rel_to._meta.object_name.lower()) + info = (rel_to._meta.app_label, rel_to._meta.model_name) self.widget.choices = self.choices output = [self.widget.render(name, value, *args, **kwargs)] if self.can_add_related: diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index cb0c116416..ef2790f2db 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -189,7 +189,7 @@ def model_detail(request, app_label, model_name): raise Http404(_("App %r not found") % app_label) model = None for m in models.get_models(app_mod): - if m._meta.object_name.lower() == model_name: + if m._meta.model_name == model_name: model = m break if model is None: @@ -224,12 +224,12 @@ def model_detail(request, app_label, model_name): fields.append({ 'name': "%s.all" % field.name, "data_type": 'List', - 'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name), + 'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name), }) fields.append({ 'name' : "%s.count" % field.name, 'data_type' : 'Integer', - 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name), + 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name), }) # Gather model methods. @@ -243,7 +243,7 @@ def model_detail(request, app_label, model_name): continue verbose = func.__doc__ if verbose: - verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', _('model:') + opts.module_name) + verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', _('model:') + opts.model_name) fields.append({ 'name': func_name, 'data_type': get_return_data_type(func_name), @@ -257,12 +257,12 @@ def model_detail(request, app_label, model_name): fields.append({ 'name' : "%s.all" % accessor, 'data_type' : 'List', - 'verbose' : utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name), + 'verbose' : utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name), }) fields.append({ 'name' : "%s.count" % accessor, 'data_type' : 'Integer', - 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name), + 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name), }) return render_to_response('admin_doc/model_detail.html', { 'root_path': urlresolvers.reverse('admin:index'), diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py index 3d17fe2754..b8ead73eb4 100644 --- a/django/contrib/auth/context_processors.py +++ b/django/contrib/auth/context_processors.py @@ -2,14 +2,14 @@ # the template system can understand. class PermLookupDict(object): - def __init__(self, user, module_name): - self.user, self.module_name = user, module_name + def __init__(self, user, app_label): + self.user, self.app_label = user, app_label def __repr__(self): return str(self.user.get_all_permissions()) def __getitem__(self, perm_name): - return self.user.has_perm("%s.%s" % (self.module_name, perm_name)) + return self.user.has_perm("%s.%s" % (self.app_label, perm_name)) def __iter__(self): # To fix 'item in perms.someapp' and __getitem__ iteraction we need to @@ -17,7 +17,7 @@ class PermLookupDict(object): raise TypeError("PermLookupDict is not iterable.") def __bool__(self): - return self.user.has_module_perms(self.module_name) + return self.user.has_module_perms(self.app_label) def __nonzero__(self): # Python 2 compatibility return type(self).__bool__(self) @@ -27,8 +27,8 @@ class PermWrapper(object): def __init__(self, user): self.user = user - def __getitem__(self, module_name): - return PermLookupDict(self.user, module_name) + def __getitem__(self, app_label): + return PermLookupDict(self.user, app_label) def __iter__(self): # I am large, I contain multitudes. @@ -41,8 +41,8 @@ class PermWrapper(object): if '.' not in perm_name: # The name refers to module. return bool(self[perm_name]) - module_name, perm_name = perm_name.split('.', 1) - return self[module_name][perm_name] + app_label, perm_name = perm_name.split('.', 1) + return self[app_label][perm_name] def auth(request): diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py index a77bba0f73..475dd255d4 100644 --- a/django/contrib/auth/management/__init__.py +++ b/django/contrib/auth/management/__init__.py @@ -17,7 +17,7 @@ from django.utils.six.moves import input def _get_permission_codename(action, opts): - return '%s_%s' % (action, opts.object_name.lower()) + return '%s_%s' % (action, opts.model_name) def _get_all_permissions(opts, ctype): diff --git a/django/contrib/comments/moderation.py b/django/contrib/comments/moderation.py index 6c56d7a8a5..6648aebb59 100644 --- a/django/contrib/comments/moderation.py +++ b/django/contrib/comments/moderation.py @@ -302,7 +302,7 @@ class Moderator(object): model_or_iterable = [model_or_iterable] for model in model_or_iterable: if model in self._registry: - raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.module_name) + raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.model_name) self._registry[model] = moderation_class(model) def unregister(self, model_or_iterable): @@ -318,7 +318,7 @@ class Moderator(object): model_or_iterable = [model_or_iterable] for model in model_or_iterable: if model not in self._registry: - raise NotModerated("The model '%s' is not currently being moderated" % model._meta.module_name) + raise NotModerated("The model '%s' is not currently being moderated" % model._meta.model_name) del self._registry[model] def pre_save_moderation(self, sender, comment, request, **kwargs): diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py index 7c02b21b6a..befd326092 100644 --- a/django/contrib/comments/views/comments.py +++ b/django/contrib/comments/views/comments.py @@ -86,10 +86,10 @@ def post_comment(request, next=None, using=None): # These first two exist for purely historical reasons. # Django v1.0 and v1.1 allowed the underscore format for # preview templates, so we have to preserve that format. - "comments/%s_%s_preview.html" % (model._meta.app_label, model._meta.module_name), + "comments/%s_%s_preview.html" % (model._meta.app_label, model._meta.model_name), "comments/%s_preview.html" % model._meta.app_label, # Now the usual directory based template hierarchy. - "comments/%s/%s/preview.html" % (model._meta.app_label, model._meta.module_name), + "comments/%s/%s/preview.html" % (model._meta.app_label, model._meta.model_name), "comments/%s/preview.html" % model._meta.app_label, "comments/preview.html", ] diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index cda4d46fe8..d849d1607e 100644 --- a/django/contrib/contenttypes/generic.py +++ b/django/contrib/contenttypes/generic.py @@ -389,7 +389,7 @@ class BaseGenericInlineFormSet(BaseModelFormSet): opts = self.model._meta self.instance = instance self.rel_name = '-'.join(( - opts.app_label, opts.object_name.lower(), + opts.app_label, opts.model_name, self.ct_field.name, self.ct_fk_field.name, )) if self.instance is None or self.instance.pk is None: @@ -409,7 +409,7 @@ class BaseGenericInlineFormSet(BaseModelFormSet): @classmethod def get_default_prefix(cls): opts = cls.model._meta - return '-'.join((opts.app_label, opts.object_name.lower(), + return '-'.join((opts.app_label, opts.model_name, cls.ct_field.name, cls.ct_fk_field.name, )) diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py index 8329ab65d9..ddd7654ed7 100644 --- a/django/contrib/contenttypes/management.py +++ b/django/contrib/contenttypes/management.py @@ -21,7 +21,7 @@ def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, * # They all have the same app_label, get the first one. app_label = app_models[0]._meta.app_label app_models = dict( - (model._meta.object_name.lower(), model) + (model._meta.model_name, model) for model in app_models ) diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py index b658655bbb..f0bd109b00 100644 --- a/django/contrib/contenttypes/models.py +++ b/django/contrib/contenttypes/models.py @@ -25,7 +25,7 @@ class ContentTypeManager(models.Manager): return model._meta def _get_from_cache(self, opts): - key = (opts.app_label, opts.object_name.lower()) + key = (opts.app_label, opts.model_name) return self.__class__._cache[self.db][key] def get_for_model(self, model, for_concrete_model=True): @@ -43,7 +43,7 @@ class ContentTypeManager(models.Manager): # django.utils.functional.__proxy__ object. ct, created = self.get_or_create( app_label = opts.app_label, - model = opts.object_name.lower(), + model = opts.model_name, defaults = {'name': smart_text(opts.verbose_name_raw)}, ) self._add_to_cache(self.db, ct) @@ -67,7 +67,7 @@ class ContentTypeManager(models.Manager): ct = self._get_from_cache(opts) except KeyError: needed_app_labels.add(opts.app_label) - needed_models.add(opts.object_name.lower()) + needed_models.add(opts.model_name) needed_opts.add(opts) else: results[model] = ct @@ -86,7 +86,7 @@ class ContentTypeManager(models.Manager): # These weren't in the cache, or the DB, create them. ct = self.create( app_label=opts.app_label, - model=opts.object_name.lower(), + model=opts.model_name, name=smart_text(opts.verbose_name_raw), ) self._add_to_cache(self.db, ct) @@ -119,7 +119,7 @@ class ContentTypeManager(models.Manager): def _add_to_cache(self, using, ct): """Insert a ContentType into the cache.""" model = ct.model_class() - key = (model._meta.app_label, model._meta.object_name.lower()) + key = (model._meta.app_label, model._meta.model_name) self.__class__._cache.setdefault(using, {})[key] = ct self.__class__._cache.setdefault(using, {})[ct.id] = ct diff --git a/django/contrib/gis/sitemaps/kml.py b/django/contrib/gis/sitemaps/kml.py index db30606b04..837fe62b62 100644 --- a/django/contrib/gis/sitemaps/kml.py +++ b/django/contrib/gis/sitemaps/kml.py @@ -30,7 +30,7 @@ class KMLSitemap(Sitemap): for field in source._meta.fields: if isinstance(field, GeometryField): kml_sources.append((source._meta.app_label, - source._meta.module_name, + source._meta.model_name, field.name)) elif isinstance(source, (list, tuple)): if len(source) != 3: diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py index c93bc90b18..5c9ea3e7bb 100644 --- a/django/core/cache/backends/db.py +++ b/django/core/cache/backends/db.py @@ -23,7 +23,7 @@ class Options(object): def __init__(self, table): self.db_table = table self.app_label = 'django_cache' - self.module_name = 'cacheentry' + self.model_name = 'cacheentry' self.verbose_name = 'cache entry' self.verbose_name_plural = 'cache entries' self.object_name = 'CacheEntry' diff --git a/django/core/management/sql.py b/django/core/management/sql.py index e46f4ae4f5..66df43e971 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -173,8 +173,8 @@ def custom_sql_for_model(model, style, connection): # Find custom SQL, if it's available. backend_name = connection.settings_dict['ENGINE'].split('.')[-1] - sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)), - os.path.join(app_dir, "%s.sql" % opts.object_name.lower())] + sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.model_name, backend_name)), + os.path.join(app_dir, "%s.sql" % opts.model_name)] for sql_file in sql_files: if os.path.exists(sql_file): with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp: diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index 37fa906280..5e07e2a006 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -143,7 +143,7 @@ def Deserializer(object_list, **options): def _get_model(model_identifier): """ - Helper to look up a model from an "app_label.module_name" string. + Helper to look up a model from an "app_label.model_name" string. """ try: Model = models.get_model(*model_identifier.split(".")) diff --git a/django/core/xheaders.py b/django/core/xheaders.py index b650a3a6d4..3766628c98 100644 --- a/django/core/xheaders.py +++ b/django/core/xheaders.py @@ -20,5 +20,5 @@ def populate_xheaders(request, response, model, object_id): if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or (hasattr(request, 'user') and request.user.is_active and request.user.is_staff)): - response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.object_name.lower()) + response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.model_name) response['X-Object-Id'] = str(object_id) diff --git a/django/db/models/base.py b/django/db/models/base.py index 38afc60991..5f058654bf 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -191,7 +191,7 @@ class ModelBase(type): if base in o2o_map: field = o2o_map[base] elif not is_proxy: - attr_name = '%s_ptr' % base._meta.module_name + attr_name = '%s_ptr' % base._meta.model_name field = OneToOneField(base, name=attr_name, auto_created=True, parent_link=True) new_class.add_to_class(attr_name, field) @@ -973,7 +973,7 @@ def method_get_order(ordered_obj, self): ############################################## def get_absolute_url(opts, func, self, *args, **kwargs): - return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs) + return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.model_name), func)(self, *args, **kwargs) ######## diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index ae792a30e7..bd2e288410 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -118,7 +118,7 @@ class RelatedField(object): self.do_related_class(other, cls) def set_attributes_from_rel(self): - self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name) + self.name = self.name or (self.rel.to._meta.model_name + '_' + self.rel.to._meta.pk.name) if self.verbose_name is None: self.verbose_name = self.rel.to._meta.verbose_name self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.name @@ -222,7 +222,7 @@ class RelatedField(object): # related object in a table-spanning query. It uses the lower-cased # object_name by default, but this can be overridden with the # "related_name" option. - return self.rel.related_name or self.opts.object_name.lower() + return self.rel.related_name or self.opts.model_name class SingleRelatedObjectDescriptor(object): @@ -983,7 +983,7 @@ class ForeignKey(RelatedField, Field): def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): try: - to_name = to._meta.object_name.lower() + to_name = to._meta.model_name except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT assert isinstance(to, six.string_types), "%s(%r) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT) else: @@ -1174,7 +1174,7 @@ def create_many_to_many_intermediary_model(field, klass): from_ = 'from_%s' % to.lower() to = 'to_%s' % to.lower() else: - from_ = klass._meta.object_name.lower() + from_ = klass._meta.model_name to = to.lower() meta = type('Meta', (object,), { 'db_table': field._get_m2m_db_table(klass._meta), diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 56edc36bec..c027105c5b 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -239,7 +239,7 @@ class AppCache(object): for model in models: # Store as 'name: model' pair in a dictionary # in the app_models dictionary - model_name = model._meta.object_name.lower() + model_name = model._meta.model_name model_dict = self.app_models.setdefault(app_label, SortedDict()) if model_name in model_dict: # The same model may be imported via different paths (e.g. diff --git a/django/db/models/options.py b/django/db/models/options.py index 952596b514..a302e2d73a 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import re from bisect import bisect +import warnings from django.conf import settings from django.db.models.fields.related import ManyToManyRel @@ -28,7 +29,7 @@ class Options(object): def __init__(self, meta, app_label=None): self.local_fields, self.local_many_to_many = [], [] self.virtual_fields = [] - self.module_name, self.verbose_name = None, None + self.model_name, self.verbose_name = None, None self.verbose_name_plural = None self.db_table = '' self.ordering = [] @@ -78,7 +79,7 @@ class Options(object): self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS # First, construct the default values for these options. self.object_name = cls.__name__ - self.module_name = self.object_name.lower() + self.model_name = self.object_name.lower() self.verbose_name = get_verbose_name(self.object_name) # Next, apply any overridden values from 'class Meta'. @@ -116,11 +117,21 @@ class Options(object): self.verbose_name_plural = string_concat(self.verbose_name, 's') del self.meta - # If the db_table wasn't provided, use the app_label + module_name. + # If the db_table wasn't provided, use the app_label + model_name. if not self.db_table: - self.db_table = "%s_%s" % (self.app_label, self.module_name) + self.db_table = "%s_%s" % (self.app_label, self.model_name) self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) + @property + def module_name(self): + """ + This property has been deprecated in favor of `model_name`. refs #19689 + """ + warnings.warn( + "Options.module_name has been deprecated in favor of model_name", + PendingDeprecationWarning, stacklevel=2) + return self.model_name + def _prepare(self, model): if self.order_with_respect_to: self.order_with_respect_to = self.get_field(self.order_with_respect_to) @@ -193,7 +204,7 @@ class Options(object): return '' % self.object_name def __str__(self): - return "%s.%s" % (smart_text(self.app_label), smart_text(self.module_name)) + return "%s.%s" % (smart_text(self.app_label), smart_text(self.model_name)) def verbose_name_raw(self): """ @@ -217,7 +228,7 @@ class Options(object): case insensitive, so we make sure we are case insensitive here. """ if self.swappable: - model_label = '%s.%s' % (self.app_label, self.object_name.lower()) + model_label = '%s.%s' % (self.app_label, self.model_name) swapped_for = getattr(settings, self.swappable, None) if swapped_for: try: @@ -371,13 +382,13 @@ class Options(object): return cache def get_add_permission(self): - return 'add_%s' % self.object_name.lower() + return 'add_%s' % self.model_name def get_change_permission(self): - return 'change_%s' % self.object_name.lower() + return 'change_%s' % self.model_name def get_delete_permission(self): - return 'delete_%s' % self.object_name.lower() + return 'delete_%s' % self.model_name def get_all_related_objects(self, local_only=False, include_hidden=False, include_proxy_eq=False): diff --git a/django/db/models/related.py b/django/db/models/related.py index 26932137ad..53645bedb9 100644 --- a/django/db/models/related.py +++ b/django/db/models/related.py @@ -16,8 +16,8 @@ class RelatedObject(object): self.model = model self.opts = model._meta self.field = field - self.name = '%s:%s' % (self.opts.app_label, self.opts.module_name) - self.var_name = self.opts.object_name.lower() + self.name = '%s:%s' % (self.opts.app_label, self.opts.model_name) + self.var_name = self.opts.model_name def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_to_currently_related=False): @@ -31,7 +31,7 @@ class RelatedObject(object): queryset = self.model._default_manager.all() if limit_to_currently_related: queryset = queryset.complex_filter( - {'%s__isnull' % self.parent_model._meta.module_name: False}) + {'%s__isnull' % self.parent_model._meta.model_name: False}) lst = [(x._get_pk_val(), smart_text(x)) for x in queryset] return first_choice + lst @@ -56,9 +56,9 @@ class RelatedObject(object): # If this is a symmetrical m2m relation on self, there is no reverse accessor. if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model: return None - return self.field.rel.related_name or (self.opts.object_name.lower() + '_set') + return self.field.rel.related_name or (self.opts.model_name + '_set') else: - return self.field.rel.related_name or (self.opts.object_name.lower()) + return self.field.rel.related_name or (self.opts.model_name) def get_cache_name(self): return "_%s_cache" % self.get_accessor_name() diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py index c27b92b85e..58302bbe23 100644 --- a/django/views/generic/detail.py +++ b/django/views/generic/detail.py @@ -84,7 +84,7 @@ class SingleObjectMixin(ContextMixin): if self.context_object_name: return self.context_object_name elif isinstance(obj, models.Model): - return obj._meta.object_name.lower() + return obj._meta.model_name else: return None @@ -144,13 +144,13 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin): if isinstance(self.object, models.Model): names.append("%s/%s%s.html" % ( self.object._meta.app_label, - self.object._meta.object_name.lower(), + self.object._meta.model_name, self.template_name_suffix )) elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model): names.append("%s/%s%s.html" % ( self.model._meta.app_label, - self.model._meta.object_name.lower(), + self.model._meta.model_name, self.template_name_suffix )) return names diff --git a/django/views/generic/list.py b/django/views/generic/list.py index 1f286168f6..08c4bbcda0 100644 --- a/django/views/generic/list.py +++ b/django/views/generic/list.py @@ -97,7 +97,7 @@ class MultipleObjectMixin(ContextMixin): if self.context_object_name: return self.context_object_name elif hasattr(object_list, 'model'): - return '%s_list' % object_list.model._meta.object_name.lower() + return '%s_list' % object_list.model._meta.model_name else: return None @@ -177,7 +177,7 @@ class MultipleObjectTemplateResponseMixin(TemplateResponseMixin): # generated ones. if hasattr(self.object_list, 'model'): opts = self.object_list.model._meta - names.append("%s/%s%s.html" % (opts.app_label, opts.object_name.lower(), self.template_name_suffix)) + names.append("%s/%s%s.html" % (opts.app_label, opts.model_name, self.template_name_suffix)) return names diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index df3d84fdae..50b9aa3c19 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -327,6 +327,8 @@ these changes. :class:`django.middleware.common.BrokenLinkEmailsMiddleware` middleware to your :setting:`MIDDLEWARE_CLASSES` setting instead. +* ``Model._meta.module_name`` was renamed to ``model_name``. + 2.0 --- diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt index 32e5172878..f86d8b8108 100644 --- a/docs/releases/1.6.txt +++ b/docs/releases/1.6.txt @@ -127,3 +127,9 @@ from your settings. If you defined your own form widgets and defined the ``_has_changed`` method on a widget, you should now define this method on the form field itself. + +``module_name`` model meta attribute +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``Model._meta.module_name`` was renamed to ``model_name``. Despite being a +private API, it will go through a regular deprecation path. diff --git a/tests/regressiontests/admin_custom_urls/models.py b/tests/regressiontests/admin_custom_urls/models.py index ef04c2aa09..55fc064835 100644 --- a/tests/regressiontests/admin_custom_urls/models.py +++ b/tests/regressiontests/admin_custom_urls/models.py @@ -42,7 +42,7 @@ class ActionAdmin(admin.ModelAdmin): return self.admin_site.admin_view(view)(*args, **kwargs) return update_wrapper(wrapper, view) - info = self.model._meta.app_label, self.model._meta.module_name + info = self.model._meta.app_label, self.model._meta.model_name view_name = '%s_%s_add' % info