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

This commit is contained in:
Simon Charette 2013-02-05 04:16:07 -05:00
parent 826d9de00e
commit ec469ade2b
32 changed files with 102 additions and 84 deletions

View File

@ -75,7 +75,7 @@ def delete_selected(modeladmin, request, queryset):
# Display the confirmation page # Display the confirmation page
return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [ 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/%s/delete_selected_confirmation.html" % app_label,
"admin/delete_selected_confirmation.html" "admin/delete_selected_confirmation.html"
], context, current_app=modeladmin.admin_site.name) ], context, current_app=modeladmin.admin_site.name)

View File

@ -371,7 +371,7 @@ class ModelAdmin(BaseModelAdmin):
return self.admin_site.admin_view(view)(*args, **kwargs) return self.admin_site.admin_view(view)(*args, **kwargs)
return update_wrapper(wrapper, view) 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('', urlpatterns = patterns('',
url(r'^$', url(r'^$',
@ -783,7 +783,7 @@ class ModelAdmin(BaseModelAdmin):
form_template = self.change_form_template form_template = self.change_form_template
return TemplateResponse(request, form_template or [ 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/%s/change_form.html" % app_label,
"admin/change_form.html" "admin/change_form.html"
], context, current_app=self.admin_site.name) ], context, current_app=self.admin_site.name)
@ -803,7 +803,7 @@ class ModelAdmin(BaseModelAdmin):
self.message_user(request, msg) self.message_user(request, msg)
if post_url_continue is None: if post_url_continue is None:
post_url_continue = reverse('admin:%s_%s_change' % post_url_continue = reverse('admin:%s_%s_change' %
(opts.app_label, opts.module_name), (opts.app_label, opts.model_name),
args=(pk_value,), args=(pk_value,),
current_app=self.admin_site.name) current_app=self.admin_site.name)
if "_popup" in request.POST: 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 msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict
self.message_user(request, msg) self.message_user(request, msg)
return HttpResponseRedirect(reverse('admin:%s_%s_change' % return HttpResponseRedirect(reverse('admin:%s_%s_change' %
(opts.app_label, opts.module_name), (opts.app_label, opts.model_name),
args=(pk_value,), args=(pk_value,),
current_app=self.admin_site.name)) current_app=self.admin_site.name))
elif "_addanother" in request.POST: elif "_addanother" in request.POST:
msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict
self.message_user(request, msg) self.message_user(request, msg)
return HttpResponseRedirect(reverse('admin:%s_%s_add' % 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)) current_app=self.admin_site.name))
else: else:
msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict
@ -867,7 +867,7 @@ class ModelAdmin(BaseModelAdmin):
opts = self.model._meta opts = self.model._meta
if self.has_change_permission(request, None): if self.has_change_permission(request, None):
post_url = reverse('admin:%s_%s_changelist' % 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) current_app=self.admin_site.name)
else: else:
post_url = reverse('admin:index', post_url = reverse('admin:index',
@ -882,7 +882,7 @@ class ModelAdmin(BaseModelAdmin):
opts = self.model._meta opts = self.model._meta
if self.has_change_permission(request, None): if self.has_change_permission(request, None):
post_url = reverse('admin:%s_%s_changelist' % 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) current_app=self.admin_site.name)
else: else:
post_url = reverse('admin:index', post_url = reverse('admin:index',
@ -1060,7 +1060,7 @@ class ModelAdmin(BaseModelAdmin):
if request.method == 'POST' and "_saveasnew" in request.POST: if request.method == 'POST' and "_saveasnew" in request.POST:
return self.add_view(request, form_url=reverse('admin:%s_%s_add' % 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)) current_app=self.admin_site.name))
ModelForm = self.get_form(request, obj) ModelForm = self.get_form(request, obj)
@ -1283,7 +1283,7 @@ class ModelAdmin(BaseModelAdmin):
context.update(extra_context or {}) context.update(extra_context or {})
return TemplateResponse(request, self.change_list_template 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/%s/change_list.html' % app_label,
'admin/change_list.html' 'admin/change_list.html'
], context, current_app=self.admin_site.name) ], context, current_app=self.admin_site.name)
@ -1323,7 +1323,7 @@ class ModelAdmin(BaseModelAdmin):
return HttpResponseRedirect(reverse('admin:index', return HttpResponseRedirect(reverse('admin:index',
current_app=self.admin_site.name)) current_app=self.admin_site.name))
return HttpResponseRedirect(reverse('admin:%s_%s_changelist' % 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)) current_app=self.admin_site.name))
object_name = force_text(opts.verbose_name) object_name = force_text(opts.verbose_name)
@ -1346,7 +1346,7 @@ class ModelAdmin(BaseModelAdmin):
context.update(extra_context or {}) context.update(extra_context or {})
return TemplateResponse(request, self.delete_confirmation_template 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/%s/delete_confirmation.html" % app_label,
"admin/delete_confirmation.html" "admin/delete_confirmation.html"
], context, current_app=self.admin_site.name) ], context, current_app=self.admin_site.name)
@ -1373,7 +1373,7 @@ class ModelAdmin(BaseModelAdmin):
} }
context.update(extra_context or {}) context.update(extra_context or {})
return TemplateResponse(request, self.object_history_template 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/%s/object_history.html" % app_label,
"admin/object_history.html" "admin/object_history.html"
], context, current_app=self.admin_site.name) ], context, current_app=self.admin_site.name)

View File

@ -247,7 +247,7 @@ class AdminSite(object):
# Add in each model's views. # Add in each model's views.
for model, model_admin in six.iteritems(self._registry): for model, model_admin in six.iteritems(self._registry):
urlpatterns += patterns('', 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)) include(model_admin.urls))
) )
return urlpatterns return urlpatterns
@ -351,7 +351,7 @@ class AdminSite(object):
# Check whether user has any perm for this module. # Check whether user has any perm for this module.
# If so, add the module to the model_list. # If so, add the module to the model_list.
if True in perms.values(): if True in perms.values():
info = (app_label, model._meta.module_name) info = (app_label, model._meta.model_name)
model_dict = { model_dict = {
'name': capfirst(model._meta.verbose_name_plural), 'name': capfirst(model._meta.verbose_name_plural),
'object_name': model._meta.object_name, 'object_name': model._meta.object_name,
@ -407,7 +407,7 @@ class AdminSite(object):
# Check whether user has any perm for this module. # Check whether user has any perm for this module.
# If so, add the module to the model_list. # If so, add the module to the model_list.
if True in perms.values(): if True in perms.values():
info = (app_label, model._meta.module_name) info = (app_label, model._meta.model_name)
model_dict = { model_dict = {
'name': capfirst(model._meta.verbose_name_plural), 'name': capfirst(model._meta.verbose_name_plural),
'object_name': model._meta.object_name, 'object_name': model._meta.object_name,

View File

@ -19,7 +19,7 @@
{% endblock %} {% endblock %}
{% endif %} {% endif %}
{% block content %}<div id="content-main"> {% 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> <div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if form.errors %} {% if form.errors %}

View File

@ -35,7 +35,7 @@
</ul> </ul>
{% endif %}{% endif %} {% endif %}{% endif %}
{% endblock %} {% 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> <div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}

View File

@ -1,4 +1,3 @@
from django.core.urlresolvers import reverse
from django import template from django import template
from django.contrib.admin.util import quote from django.contrib.admin.util import quote
@ -6,7 +5,7 @@ register = template.Library()
@register.filter @register.filter
def admin_urlname(value, arg): 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 @register.filter

View File

@ -116,7 +116,7 @@ def get_deleted_objects(objs, opts, user, admin_site, using):
admin_url = reverse('%s:%s_%s_change' admin_url = reverse('%s:%s_%s_change'
% (admin_site.name, % (admin_site.name,
opts.app_label, opts.app_label,
opts.object_name.lower()), opts.model_name),
None, (quote(obj._get_pk_val()),)) None, (quote(obj._get_pk_val()),))
p = '%s.%s' % (opts.app_label, p = '%s.%s' % (opts.app_label,
opts.get_delete_permission()) opts.get_delete_permission())

View File

@ -379,6 +379,6 @@ class ChangeList(object):
def url_for_result(self, result): def url_for_result(self, result):
pk = getattr(result, self.pk_attname) pk = getattr(result, self.pk_attname)
return reverse('admin:%s_%s_change' % (self.opts.app_label, return reverse('admin:%s_%s_change' % (self.opts.app_label,
self.opts.module_name), self.opts.model_name),
args=(quote(pk),), args=(quote(pk),),
current_app=self.model_admin.admin_site.name) current_app=self.model_admin.admin_site.name)

View File

@ -147,7 +147,7 @@ class ForeignKeyRawIdWidget(forms.TextInput):
# The related object is registered with the same AdminSite # The related object is registered with the same AdminSite
related_url = reverse('admin:%s_%s_changelist' % related_url = reverse('admin:%s_%s_changelist' %
(rel_to._meta.app_label, (rel_to._meta.app_label,
rel_to._meta.module_name), rel_to._meta.model_name),
current_app=self.admin_site.name) current_app=self.admin_site.name)
params = self.url_parameters() params = self.url_parameters()
@ -247,7 +247,7 @@ class RelatedFieldWidgetWrapper(forms.Widget):
def render(self, name, value, *args, **kwargs): def render(self, name, value, *args, **kwargs):
rel_to = self.rel.to 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 self.widget.choices = self.choices
output = [self.widget.render(name, value, *args, **kwargs)] output = [self.widget.render(name, value, *args, **kwargs)]
if self.can_add_related: if self.can_add_related:

View File

@ -189,7 +189,7 @@ def model_detail(request, app_label, model_name):
raise Http404(_("App %r not found") % app_label) raise Http404(_("App %r not found") % app_label)
model = None model = None
for m in models.get_models(app_mod): 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 model = m
break break
if model is None: if model is None:
@ -224,12 +224,12 @@ def model_detail(request, app_label, model_name):
fields.append({ fields.append({
'name': "%s.all" % field.name, 'name': "%s.all" % field.name,
"data_type": 'List', "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({ fields.append({
'name' : "%s.count" % field.name, 'name' : "%s.count" % field.name,
'data_type' : 'Integer', '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. # Gather model methods.
@ -243,7 +243,7 @@ def model_detail(request, app_label, model_name):
continue continue
verbose = func.__doc__ verbose = func.__doc__
if verbose: 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({ fields.append({
'name': func_name, 'name': func_name,
'data_type': get_return_data_type(func_name), 'data_type': get_return_data_type(func_name),
@ -257,12 +257,12 @@ def model_detail(request, app_label, model_name):
fields.append({ fields.append({
'name' : "%s.all" % accessor, 'name' : "%s.all" % accessor,
'data_type' : 'List', '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({ fields.append({
'name' : "%s.count" % accessor, 'name' : "%s.count" % accessor,
'data_type' : 'Integer', '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', { return render_to_response('admin_doc/model_detail.html', {
'root_path': urlresolvers.reverse('admin:index'), 'root_path': urlresolvers.reverse('admin:index'),

View File

@ -2,14 +2,14 @@
# the template system can understand. # the template system can understand.
class PermLookupDict(object): class PermLookupDict(object):
def __init__(self, user, module_name): def __init__(self, user, app_label):
self.user, self.module_name = user, module_name self.user, self.app_label = user, app_label
def __repr__(self): def __repr__(self):
return str(self.user.get_all_permissions()) return str(self.user.get_all_permissions())
def __getitem__(self, perm_name): 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): def __iter__(self):
# To fix 'item in perms.someapp' and __getitem__ iteraction we need to # 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.") raise TypeError("PermLookupDict is not iterable.")
def __bool__(self): 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 def __nonzero__(self): # Python 2 compatibility
return type(self).__bool__(self) return type(self).__bool__(self)
@ -27,8 +27,8 @@ class PermWrapper(object):
def __init__(self, user): def __init__(self, user):
self.user = user self.user = user
def __getitem__(self, module_name): def __getitem__(self, app_label):
return PermLookupDict(self.user, module_name) return PermLookupDict(self.user, app_label)
def __iter__(self): def __iter__(self):
# I am large, I contain multitudes. # I am large, I contain multitudes.
@ -41,8 +41,8 @@ class PermWrapper(object):
if '.' not in perm_name: if '.' not in perm_name:
# The name refers to module. # The name refers to module.
return bool(self[perm_name]) return bool(self[perm_name])
module_name, perm_name = perm_name.split('.', 1) app_label, perm_name = perm_name.split('.', 1)
return self[module_name][perm_name] return self[app_label][perm_name]
def auth(request): def auth(request):

View File

@ -17,7 +17,7 @@ from django.utils.six.moves import input
def _get_permission_codename(action, opts): 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): def _get_all_permissions(opts, ctype):

View File

@ -302,7 +302,7 @@ class Moderator(object):
model_or_iterable = [model_or_iterable] model_or_iterable = [model_or_iterable]
for model in model_or_iterable: for model in model_or_iterable:
if model in self._registry: 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) self._registry[model] = moderation_class(model)
def unregister(self, model_or_iterable): def unregister(self, model_or_iterable):
@ -318,7 +318,7 @@ class Moderator(object):
model_or_iterable = [model_or_iterable] model_or_iterable = [model_or_iterable]
for model in model_or_iterable: for model in model_or_iterable:
if model not in self._registry: 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] del self._registry[model]
def pre_save_moderation(self, sender, comment, request, **kwargs): def pre_save_moderation(self, sender, comment, request, **kwargs):

View File

@ -86,10 +86,10 @@ def post_comment(request, next=None, using=None):
# These first two exist for purely historical reasons. # These first two exist for purely historical reasons.
# Django v1.0 and v1.1 allowed the underscore format for # Django v1.0 and v1.1 allowed the underscore format for
# preview templates, so we have to preserve that format. # 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, "comments/%s_preview.html" % model._meta.app_label,
# Now the usual directory based template hierarchy. # 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/%s/preview.html" % model._meta.app_label,
"comments/preview.html", "comments/preview.html",
] ]

View File

@ -389,7 +389,7 @@ class BaseGenericInlineFormSet(BaseModelFormSet):
opts = self.model._meta opts = self.model._meta
self.instance = instance self.instance = instance
self.rel_name = '-'.join(( 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, self.ct_field.name, self.ct_fk_field.name,
)) ))
if self.instance is None or self.instance.pk is None: if self.instance is None or self.instance.pk is None:
@ -409,7 +409,7 @@ class BaseGenericInlineFormSet(BaseModelFormSet):
@classmethod @classmethod
def get_default_prefix(cls): def get_default_prefix(cls):
opts = cls.model._meta 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, cls.ct_field.name, cls.ct_fk_field.name,
)) ))

View File

@ -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. # They all have the same app_label, get the first one.
app_label = app_models[0]._meta.app_label app_label = app_models[0]._meta.app_label
app_models = dict( app_models = dict(
(model._meta.object_name.lower(), model) (model._meta.model_name, model)
for model in app_models for model in app_models
) )

View File

@ -25,7 +25,7 @@ class ContentTypeManager(models.Manager):
return model._meta return model._meta
def _get_from_cache(self, opts): 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] return self.__class__._cache[self.db][key]
def get_for_model(self, model, for_concrete_model=True): def get_for_model(self, model, for_concrete_model=True):
@ -43,7 +43,7 @@ class ContentTypeManager(models.Manager):
# django.utils.functional.__proxy__ object. # django.utils.functional.__proxy__ object.
ct, created = self.get_or_create( ct, created = self.get_or_create(
app_label = opts.app_label, app_label = opts.app_label,
model = opts.object_name.lower(), model = opts.model_name,
defaults = {'name': smart_text(opts.verbose_name_raw)}, defaults = {'name': smart_text(opts.verbose_name_raw)},
) )
self._add_to_cache(self.db, ct) self._add_to_cache(self.db, ct)
@ -67,7 +67,7 @@ class ContentTypeManager(models.Manager):
ct = self._get_from_cache(opts) ct = self._get_from_cache(opts)
except KeyError: except KeyError:
needed_app_labels.add(opts.app_label) needed_app_labels.add(opts.app_label)
needed_models.add(opts.object_name.lower()) needed_models.add(opts.model_name)
needed_opts.add(opts) needed_opts.add(opts)
else: else:
results[model] = ct results[model] = ct
@ -86,7 +86,7 @@ class ContentTypeManager(models.Manager):
# These weren't in the cache, or the DB, create them. # These weren't in the cache, or the DB, create them.
ct = self.create( ct = self.create(
app_label=opts.app_label, app_label=opts.app_label,
model=opts.object_name.lower(), model=opts.model_name,
name=smart_text(opts.verbose_name_raw), name=smart_text(opts.verbose_name_raw),
) )
self._add_to_cache(self.db, ct) self._add_to_cache(self.db, ct)
@ -119,7 +119,7 @@ class ContentTypeManager(models.Manager):
def _add_to_cache(self, using, ct): def _add_to_cache(self, using, ct):
"""Insert a ContentType into the cache.""" """Insert a ContentType into the cache."""
model = ct.model_class() 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, {})[key] = ct
self.__class__._cache.setdefault(using, {})[ct.id] = ct self.__class__._cache.setdefault(using, {})[ct.id] = ct

View File

@ -30,7 +30,7 @@ class KMLSitemap(Sitemap):
for field in source._meta.fields: for field in source._meta.fields:
if isinstance(field, GeometryField): if isinstance(field, GeometryField):
kml_sources.append((source._meta.app_label, kml_sources.append((source._meta.app_label,
source._meta.module_name, source._meta.model_name,
field.name)) field.name))
elif isinstance(source, (list, tuple)): elif isinstance(source, (list, tuple)):
if len(source) != 3: if len(source) != 3:

View File

@ -23,7 +23,7 @@ class Options(object):
def __init__(self, table): def __init__(self, table):
self.db_table = table self.db_table = table
self.app_label = 'django_cache' self.app_label = 'django_cache'
self.module_name = 'cacheentry' self.model_name = 'cacheentry'
self.verbose_name = 'cache entry' self.verbose_name = 'cache entry'
self.verbose_name_plural = 'cache entries' self.verbose_name_plural = 'cache entries'
self.object_name = 'CacheEntry' self.object_name = 'CacheEntry'

View File

@ -173,8 +173,8 @@ def custom_sql_for_model(model, style, connection):
# Find custom SQL, if it's available. # Find custom SQL, if it's available.
backend_name = connection.settings_dict['ENGINE'].split('.')[-1] backend_name = connection.settings_dict['ENGINE'].split('.')[-1]
sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)), sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.model_name, backend_name)),
os.path.join(app_dir, "%s.sql" % opts.object_name.lower())] os.path.join(app_dir, "%s.sql" % opts.model_name)]
for sql_file in sql_files: for sql_file in sql_files:
if os.path.exists(sql_file): if os.path.exists(sql_file):
with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp: with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp:

View File

@ -143,7 +143,7 @@ def Deserializer(object_list, **options):
def _get_model(model_identifier): 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: try:
Model = models.get_model(*model_identifier.split(".")) Model = models.get_model(*model_identifier.split("."))

View File

@ -20,5 +20,5 @@ def populate_xheaders(request, response, model, object_id):
if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
or (hasattr(request, 'user') and request.user.is_active or (hasattr(request, 'user') and request.user.is_active
and request.user.is_staff)): 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) response['X-Object-Id'] = str(object_id)

View File

@ -191,7 +191,7 @@ class ModelBase(type):
if base in o2o_map: if base in o2o_map:
field = o2o_map[base] field = o2o_map[base]
elif not is_proxy: 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, field = OneToOneField(base, name=attr_name,
auto_created=True, parent_link=True) auto_created=True, parent_link=True)
new_class.add_to_class(attr_name, field) 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): 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 File

@ -118,7 +118,7 @@ class RelatedField(object):
self.do_related_class(other, cls) self.do_related_class(other, cls)
def set_attributes_from_rel(self): 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: if self.verbose_name is None:
self.verbose_name = self.rel.to._meta.verbose_name self.verbose_name = self.rel.to._meta.verbose_name
self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.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 # related object in a table-spanning query. It uses the lower-cased
# object_name by default, but this can be overridden with the # object_name by default, but this can be overridden with the
# "related_name" option. # "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): class SingleRelatedObjectDescriptor(object):
@ -983,7 +983,7 @@ class ForeignKey(RelatedField, Field):
def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs):
try: 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 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) 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: else:
@ -1174,7 +1174,7 @@ def create_many_to_many_intermediary_model(field, klass):
from_ = 'from_%s' % to.lower() from_ = 'from_%s' % to.lower()
to = 'to_%s' % to.lower() to = 'to_%s' % to.lower()
else: else:
from_ = klass._meta.object_name.lower() from_ = klass._meta.model_name
to = to.lower() to = to.lower()
meta = type('Meta', (object,), { meta = type('Meta', (object,), {
'db_table': field._get_m2m_db_table(klass._meta), 'db_table': field._get_m2m_db_table(klass._meta),

View File

@ -239,7 +239,7 @@ class AppCache(object):
for model in models: for model in models:
# Store as 'name: model' pair in a dictionary # Store as 'name: model' pair in a dictionary
# in the app_models 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()) model_dict = self.app_models.setdefault(app_label, SortedDict())
if model_name in model_dict: if model_name in model_dict:
# The same model may be imported via different paths (e.g. # The same model may be imported via different paths (e.g.

View File

@ -2,6 +2,7 @@ from __future__ import unicode_literals
import re import re
from bisect import bisect from bisect import bisect
import warnings
from django.conf import settings from django.conf import settings
from django.db.models.fields.related import ManyToManyRel from django.db.models.fields.related import ManyToManyRel
@ -28,7 +29,7 @@ class Options(object):
def __init__(self, meta, app_label=None): def __init__(self, meta, app_label=None):
self.local_fields, self.local_many_to_many = [], [] self.local_fields, self.local_many_to_many = [], []
self.virtual_fields = [] 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.verbose_name_plural = None
self.db_table = '' self.db_table = ''
self.ordering = [] self.ordering = []
@ -78,7 +79,7 @@ class Options(object):
self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS
# First, construct the default values for these options. # First, construct the default values for these options.
self.object_name = cls.__name__ 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) self.verbose_name = get_verbose_name(self.object_name)
# Next, apply any overridden values from 'class Meta'. # 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') self.verbose_name_plural = string_concat(self.verbose_name, 's')
del self.meta 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: 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()) 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): def _prepare(self, model):
if self.order_with_respect_to: if self.order_with_respect_to:
self.order_with_respect_to = self.get_field(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 '<Options for %s>' % self.object_name return '<Options for %s>' % self.object_name
def __str__(self): 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): def verbose_name_raw(self):
""" """
@ -217,7 +228,7 @@ class Options(object):
case insensitive, so we make sure we are case insensitive here. case insensitive, so we make sure we are case insensitive here.
""" """
if self.swappable: 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) swapped_for = getattr(settings, self.swappable, None)
if swapped_for: if swapped_for:
try: try:
@ -371,13 +382,13 @@ class Options(object):
return cache return cache
def get_add_permission(self): def get_add_permission(self):
return 'add_%s' % self.object_name.lower() return 'add_%s' % self.model_name
def get_change_permission(self): def get_change_permission(self):
return 'change_%s' % self.object_name.lower() return 'change_%s' % self.model_name
def get_delete_permission(self): 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, def get_all_related_objects(self, local_only=False, include_hidden=False,
include_proxy_eq=False): include_proxy_eq=False):

View File

@ -16,8 +16,8 @@ class RelatedObject(object):
self.model = model self.model = model
self.opts = model._meta self.opts = model._meta
self.field = field self.field = field
self.name = '%s:%s' % (self.opts.app_label, self.opts.module_name) self.name = '%s:%s' % (self.opts.app_label, self.opts.model_name)
self.var_name = self.opts.object_name.lower() self.var_name = self.opts.model_name
def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH,
limit_to_currently_related=False): limit_to_currently_related=False):
@ -31,7 +31,7 @@ class RelatedObject(object):
queryset = self.model._default_manager.all() queryset = self.model._default_manager.all()
if limit_to_currently_related: if limit_to_currently_related:
queryset = queryset.complex_filter( 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] lst = [(x._get_pk_val(), smart_text(x)) for x in queryset]
return first_choice + lst 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 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: if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model:
return None 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: 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): def get_cache_name(self):
return "_%s_cache" % self.get_accessor_name() return "_%s_cache" % self.get_accessor_name()

View File

@ -84,7 +84,7 @@ class SingleObjectMixin(ContextMixin):
if self.context_object_name: if self.context_object_name:
return self.context_object_name return self.context_object_name
elif isinstance(obj, models.Model): elif isinstance(obj, models.Model):
return obj._meta.object_name.lower() return obj._meta.model_name
else: else:
return None return None
@ -144,13 +144,13 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
if isinstance(self.object, models.Model): if isinstance(self.object, models.Model):
names.append("%s/%s%s.html" % ( names.append("%s/%s%s.html" % (
self.object._meta.app_label, self.object._meta.app_label,
self.object._meta.object_name.lower(), self.object._meta.model_name,
self.template_name_suffix self.template_name_suffix
)) ))
elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model): elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model):
names.append("%s/%s%s.html" % ( names.append("%s/%s%s.html" % (
self.model._meta.app_label, self.model._meta.app_label,
self.model._meta.object_name.lower(), self.model._meta.model_name,
self.template_name_suffix self.template_name_suffix
)) ))
return names return names

View File

@ -97,7 +97,7 @@ class MultipleObjectMixin(ContextMixin):
if self.context_object_name: if self.context_object_name:
return self.context_object_name return self.context_object_name
elif hasattr(object_list, 'model'): 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: else:
return None return None
@ -177,7 +177,7 @@ class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
# generated ones. # generated ones.
if hasattr(self.object_list, 'model'): if hasattr(self.object_list, 'model'):
opts = self.object_list.model._meta 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 return names

View File

@ -327,6 +327,8 @@ these changes.
:class:`django.middleware.common.BrokenLinkEmailsMiddleware` middleware to :class:`django.middleware.common.BrokenLinkEmailsMiddleware` middleware to
your :setting:`MIDDLEWARE_CLASSES` setting instead. your :setting:`MIDDLEWARE_CLASSES` setting instead.
* ``Model._meta.module_name`` was renamed to ``model_name``.
2.0 2.0
--- ---

View File

@ -127,3 +127,9 @@ from your settings.
If you defined your own form widgets and defined the ``_has_changed`` method 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. 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 File

@ -42,7 +42,7 @@ class ActionAdmin(admin.ModelAdmin):
return self.admin_site.admin_view(view)(*args, **kwargs) return self.admin_site.admin_view(view)(*args, **kwargs)
return update_wrapper(wrapper, view) 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 view_name = '%s_%s_add' % info