Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #19689 -- Renamed `Model._meta.module_name` to `model_name`.

  • Loading branch information...
commit ec469ade2b04b94bfeb59fb0fc7d9300470be615 1 parent 826d9de
@charettes charettes authored
Showing with 102 additions and 84 deletions.
  1. +1 −1  django/contrib/admin/actions.py
  2. +12 −12 django/contrib/admin/options.py
  3. +3 −3 django/contrib/admin/sites.py
  4. +1 −1  django/contrib/admin/templates/admin/auth/user/change_password.html
  5. +1 −1  django/contrib/admin/templates/admin/change_form.html
  6. +1 −2  django/contrib/admin/templatetags/admin_urls.py
  7. +1 −1  django/contrib/admin/util.py
  8. +1 −1  django/contrib/admin/views/main.py
  9. +2 −2 django/contrib/admin/widgets.py
  10. +6 −6 django/contrib/admindocs/views.py
  11. +8 −8 django/contrib/auth/context_processors.py
  12. +1 −1  django/contrib/auth/management/__init__.py
  13. +2 −2 django/contrib/comments/moderation.py
  14. +2 −2 django/contrib/comments/views/comments.py
  15. +2 −2 django/contrib/contenttypes/generic.py
  16. +1 −1  django/contrib/contenttypes/management.py
  17. +5 −5 django/contrib/contenttypes/models.py
  18. +1 −1  django/contrib/gis/sitemaps/kml.py
  19. +1 −1  django/core/cache/backends/db.py
  20. +2 −2 django/core/management/sql.py
  21. +1 −1  django/core/serializers/python.py
  22. +1 −1  django/core/xheaders.py
  23. +2 −2 django/db/models/base.py
  24. +4 −4 django/db/models/fields/related.py
  25. +1 −1  django/db/models/loading.py
  26. +20 −9 django/db/models/options.py
  27. +5 −5 django/db/models/related.py
  28. +3 −3 django/views/generic/detail.py
  29. +2 −2 django/views/generic/list.py
  30. +2 −0  docs/internals/deprecation.txt
  31. +6 −0 docs/releases/1.6.txt
  32. +1 −1  tests/regressiontests/admin_custom_urls/models.py
View
2  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)
View
24 django/contrib/admin/options.py
@@ -371,7 +371,7 @@ def wrapper(*args, **kwargs):
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 @@ def render_change_form(self, request, context, add=False, change=False, form_url
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 @@ def response_add(self, request, obj, post_url_continue=None):
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 @@ def response_change(self, request, obj):
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 @@ def response_post_save_add(self, request, obj):
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 @@ def response_post_save_change(self, request, obj):
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 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
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 @@ def changelist_view(self, request, extra_context=None):
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 @@ def delete_view(self, request, object_id, extra_context=None):
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 @@ def delete_view(self, request, object_id, extra_context=None):
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 @@ def history_view(self, request, object_id, extra_context=None):
}
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)
View
6 django/contrib/admin/sites.py
@@ -247,7 +247,7 @@ def wrapper(*args, **kwargs):
# 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 @@ def index(self, request, extra_context=None):
# 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 @@ def app_index(self, request, app_label, extra_context=None):
# 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,
View
2  django/contrib/admin/templates/admin/auth/user/change_password.html
@@ -19,7 +19,7 @@
{% endblock %}
{% endif %}
{% block content %}<div id="content-main">
-<form action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
+<form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if form.errors %}
View
2  django/contrib/admin/templates/admin/change_form.html
@@ -35,7 +35,7 @@
</ul>
{% endif %}{% endif %}
{% endblock %}
-<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
+<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}
View
3  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.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
View
2  django/contrib/admin/util.py
@@ -116,7 +116,7 @@ def format_callback(obj):
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())
View
2  django/contrib/admin/views/main.py
@@ -379,6 +379,6 @@ def construct_search(field_name):
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)
View
4 django/contrib/admin/widgets.py
@@ -147,7 +147,7 @@ def render(self, name, value, attrs=None):
# 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 @@ def media(self):
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:
View
12 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'),
View
16 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 @@ def __iter__(self):
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 @@ def __contains__(self, perm_name):
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):
View
2  django/contrib/auth/management/__init__.py
@@ -17,7 +17,7 @@
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):
View
4 django/contrib/comments/moderation.py
@@ -302,7 +302,7 @@ def register(self, model_or_iterable, moderation_class):
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 @@ def unregister(self, model_or_iterable):
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):
View
4 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",
]
View
4 django/contrib/contenttypes/generic.py
@@ -389,7 +389,7 @@ def __init__(self, data=None, files=None, instance=None, save_as_new=None,
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 @@ def __init__(self, data=None, files=None, instance=None, save_as_new=None,
@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,
))
View
2  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
)
View
10 django/contrib/contenttypes/models.py
@@ -25,7 +25,7 @@ def _get_opts(self, model, for_concrete_model):
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 @@ def get_for_model(self, model, for_concrete_model=True):
# 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 @@ def get_for_models(self, *models, **kwargs):
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 @@ def get_for_models(self, *models, **kwargs):
# 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 @@ def clear_cache(self):
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
View
2  django/contrib/gis/sitemaps/kml.py
@@ -30,7 +30,7 @@ def _build_kml_sources(self, sources):
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:
View
2  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'
View
4 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:
View
2  django/core/serializers/python.py
@@ -143,7 +143,7 @@ def m2m_convert(value):
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("."))
View
2  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)
View
4 django/db/models/base.py
@@ -191,7 +191,7 @@ def __new__(cls, name, bases, attrs):
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)
########
View
8 django/db/models/fields/related.py
@@ -118,7 +118,7 @@ def resolve_related_class(field, model, cls):
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 @@ def related_query_name(self):
# 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 set_managed(field, model, cls):
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),
View
2  django/db/models/loading.py
@@ -239,7 +239,7 @@ def register_models(self, app_label, *models):
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.
View
29 django/db/models/options.py
@@ -2,6 +2,7 @@
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 @@ def contribute_to_class(self, cls, name):
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 @@ def contribute_to_class(self, cls, name):
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 @@ def __repr__(self):
return '<Options for %s>' % 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 @@ def _swapped(self):
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 @@ def init_name_map(self):
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):
View
10 django/db/models/related.py
@@ -16,8 +16,8 @@ def __init__(self, parent_model, model, field):
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 @@ def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH,
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 @@ def get_accessor_name(self):
# 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()
View
6 django/views/generic/detail.py
@@ -84,7 +84,7 @@ def get_context_object_name(self, obj):
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 @@ def get_template_names(self):
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
View
4 django/views/generic/list.py
@@ -97,7 +97,7 @@ def get_context_object_name(self, object_list):
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 @@ def get_template_names(self):
# 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
View
2  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
---
View
6 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.
View
2  tests/regressiontests/admin_custom_urls/models.py
@@ -42,7 +42,7 @@ def wrapper(*args, **kwargs):
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

1 comment on commit ec469ad

@timgraham
Owner

Is model_name still considered private API? (#20853)

Please sign in to comment.
Something went wrong with that request. Please try again.