-
From f5e7de26d250d59386a0f75f9dfadd7cdf44dd89 Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Mon, 4 Feb 2013 19:42:40 -0500
Subject: [PATCH] Fixed #19689 -- Deprecated model meta's module_name in favor
of model_name.
---
django/contrib/admin/actions.py | 2 +-
django/contrib/admin/options.py | 24 ++++++++--------
django/contrib/admin/sites.py | 6 ++--
.../templates/admin/auth/user/change_password.html | 2 +-
.../contrib/admin/templates/admin/change_form.html | 2 +-
django/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 | 4 +++
docs/releases/1.6.txt | 6 ++++
tests/regressiontests/admin_custom_urls/models.py | 2 +-
32 files changed, 104 insertions(+), 84 deletions(-)
diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py
index 2011017..d11ba3d 100644
a
|
b
|
def delete_selected(modeladmin, request, queryset):
|
75 | 75 | |
76 | 76 | # Display the confirmation page |
77 | 77 | return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [ |
78 | | "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.object_name.lower()), |
| 78 | "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.model_name), |
79 | 79 | "admin/%s/delete_selected_confirmation.html" % app_label, |
80 | 80 | "admin/delete_selected_confirmation.html" |
81 | 81 | ], context, current_app=modeladmin.admin_site.name) |
-
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 8e0aacc..8de3112 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
371 | 371 | return self.admin_site.admin_view(view)(*args, **kwargs) |
372 | 372 | return update_wrapper(wrapper, view) |
373 | 373 | |
374 | | info = self.model._meta.app_label, self.model._meta.module_name |
| 374 | info = self.model._meta.app_label, self.model._meta.model_name |
375 | 375 | |
376 | 376 | urlpatterns = patterns('', |
377 | 377 | url(r'^$', |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
783 | 783 | form_template = self.change_form_template |
784 | 784 | |
785 | 785 | return TemplateResponse(request, form_template or [ |
786 | | "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), |
| 786 | "admin/%s/%s/change_form.html" % (app_label, opts.model_name), |
787 | 787 | "admin/%s/change_form.html" % app_label, |
788 | 788 | "admin/change_form.html" |
789 | 789 | ], context, current_app=self.admin_site.name) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
803 | 803 | self.message_user(request, msg) |
804 | 804 | if post_url_continue is None: |
805 | 805 | post_url_continue = reverse('admin:%s_%s_change' % |
806 | | (opts.app_label, opts.module_name), |
| 806 | (opts.app_label, opts.model_name), |
807 | 807 | args=(pk_value,), |
808 | 808 | current_app=self.admin_site.name) |
809 | 809 | if "_popup" in request.POST: |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
845 | 845 | msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict |
846 | 846 | self.message_user(request, msg) |
847 | 847 | return HttpResponseRedirect(reverse('admin:%s_%s_change' % |
848 | | (opts.app_label, opts.module_name), |
| 848 | (opts.app_label, opts.model_name), |
849 | 849 | args=(pk_value,), |
850 | 850 | current_app=self.admin_site.name)) |
851 | 851 | elif "_addanother" in request.POST: |
852 | 852 | msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict |
853 | 853 | self.message_user(request, msg) |
854 | 854 | return HttpResponseRedirect(reverse('admin:%s_%s_add' % |
855 | | (opts.app_label, opts.module_name), |
| 855 | (opts.app_label, opts.model_name), |
856 | 856 | current_app=self.admin_site.name)) |
857 | 857 | else: |
858 | 858 | msg = _('The %(name)s "%(obj)s" was changed successfully.') % msg_dict |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
867 | 867 | opts = self.model._meta |
868 | 868 | if self.has_change_permission(request, None): |
869 | 869 | post_url = reverse('admin:%s_%s_changelist' % |
870 | | (opts.app_label, opts.module_name), |
| 870 | (opts.app_label, opts.model_name), |
871 | 871 | current_app=self.admin_site.name) |
872 | 872 | else: |
873 | 873 | post_url = reverse('admin:index', |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
882 | 882 | opts = self.model._meta |
883 | 883 | if self.has_change_permission(request, None): |
884 | 884 | post_url = reverse('admin:%s_%s_changelist' % |
885 | | (opts.app_label, opts.module_name), |
| 885 | (opts.app_label, opts.model_name), |
886 | 886 | current_app=self.admin_site.name) |
887 | 887 | else: |
888 | 888 | post_url = reverse('admin:index', |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1060 | 1060 | |
1061 | 1061 | if request.method == 'POST' and "_saveasnew" in request.POST: |
1062 | 1062 | return self.add_view(request, form_url=reverse('admin:%s_%s_add' % |
1063 | | (opts.app_label, opts.module_name), |
| 1063 | (opts.app_label, opts.model_name), |
1064 | 1064 | current_app=self.admin_site.name)) |
1065 | 1065 | |
1066 | 1066 | ModelForm = self.get_form(request, obj) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1283 | 1283 | context.update(extra_context or {}) |
1284 | 1284 | |
1285 | 1285 | return TemplateResponse(request, self.change_list_template or [ |
1286 | | 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), |
| 1286 | 'admin/%s/%s/change_list.html' % (app_label, opts.model_name), |
1287 | 1287 | 'admin/%s/change_list.html' % app_label, |
1288 | 1288 | 'admin/change_list.html' |
1289 | 1289 | ], context, current_app=self.admin_site.name) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1323 | 1323 | return HttpResponseRedirect(reverse('admin:index', |
1324 | 1324 | current_app=self.admin_site.name)) |
1325 | 1325 | return HttpResponseRedirect(reverse('admin:%s_%s_changelist' % |
1326 | | (opts.app_label, opts.module_name), |
| 1326 | (opts.app_label, opts.model_name), |
1327 | 1327 | current_app=self.admin_site.name)) |
1328 | 1328 | |
1329 | 1329 | object_name = force_text(opts.verbose_name) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1346 | 1346 | context.update(extra_context or {}) |
1347 | 1347 | |
1348 | 1348 | return TemplateResponse(request, self.delete_confirmation_template or [ |
1349 | | "admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()), |
| 1349 | "admin/%s/%s/delete_confirmation.html" % (app_label, opts.model_name), |
1350 | 1350 | "admin/%s/delete_confirmation.html" % app_label, |
1351 | 1351 | "admin/delete_confirmation.html" |
1352 | 1352 | ], context, current_app=self.admin_site.name) |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1373 | 1373 | } |
1374 | 1374 | context.update(extra_context or {}) |
1375 | 1375 | return TemplateResponse(request, self.object_history_template or [ |
1376 | | "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()), |
| 1376 | "admin/%s/%s/object_history.html" % (app_label, opts.model_name), |
1377 | 1377 | "admin/%s/object_history.html" % app_label, |
1378 | 1378 | "admin/object_history.html" |
1379 | 1379 | ], context, current_app=self.admin_site.name) |
-
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 1854170..07d1ec7 100644
a
|
b
|
class AdminSite(object):
|
247 | 247 | # Add in each model's views. |
248 | 248 | for model, model_admin in six.iteritems(self._registry): |
249 | 249 | urlpatterns += patterns('', |
250 | | url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name), |
| 250 | url(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), |
251 | 251 | include(model_admin.urls)) |
252 | 252 | ) |
253 | 253 | return urlpatterns |
… |
… |
class AdminSite(object):
|
351 | 351 | # Check whether user has any perm for this module. |
352 | 352 | # If so, add the module to the model_list. |
353 | 353 | if True in perms.values(): |
354 | | info = (app_label, model._meta.module_name) |
| 354 | info = (app_label, model._meta.model_name) |
355 | 355 | model_dict = { |
356 | 356 | 'name': capfirst(model._meta.verbose_name_plural), |
357 | 357 | 'object_name': model._meta.object_name, |
… |
… |
class AdminSite(object):
|
407 | 407 | # Check whether user has any perm for this module. |
408 | 408 | # If so, add the module to the model_list. |
409 | 409 | if True in perms.values(): |
410 | | info = (app_label, model._meta.module_name) |
| 410 | info = (app_label, model._meta.model_name) |
411 | 411 | model_dict = { |
412 | 412 | 'name': capfirst(model._meta.verbose_name_plural), |
413 | 413 | '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 83a9c48..9d1b917 100644
a
|
b
|
|
19 | 19 | {% endblock %} |
20 | 20 | {% endif %} |
21 | 21 | {% block content %}<div id="content-main"> |
22 | | <form action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %} |
| 22 | <form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %} |
23 | 23 | <div> |
24 | 24 | {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} |
25 | 25 | {% if form.errors %} |
-
diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html
index 4884696..daf3775 100644
a
|
b
|
|
35 | 35 | </ul> |
36 | 36 | {% endif %}{% endif %} |
37 | 37 | {% endblock %} |
38 | | <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 %} |
| 38 | <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 %} |
39 | 39 | <div> |
40 | 40 | {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} |
41 | 41 | {% 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 90e81b0..bca95d9 100644
a
|
b
|
|
1 | | from django.core.urlresolvers import reverse |
2 | 1 | from django import template |
3 | 2 | from django.contrib.admin.util import quote |
4 | 3 | |
… |
… |
register = template.Library()
|
6 | 5 | |
7 | 6 | @register.filter |
8 | 7 | def admin_urlname(value, arg): |
9 | | return 'admin:%s_%s_%s' % (value.app_label, value.module_name, arg) |
| 8 | return 'admin:%s_%s_%s' % (value.app_label, value.model_name, arg) |
10 | 9 | |
11 | 10 | |
12 | 11 | @register.filter |
-
diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
index 07013d1..133a8ad 100644
a
|
b
|
def get_deleted_objects(objs, opts, user, admin_site, using):
|
116 | 116 | admin_url = reverse('%s:%s_%s_change' |
117 | 117 | % (admin_site.name, |
118 | 118 | opts.app_label, |
119 | | opts.object_name.lower()), |
| 119 | opts.model_name), |
120 | 120 | None, (quote(obj._get_pk_val()),)) |
121 | 121 | p = '%s.%s' % (opts.app_label, |
122 | 122 | opts.get_delete_permission()) |
-
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index be7067f..4b296b3 100644
a
|
b
|
class ChangeList(object):
|
379 | 379 | def url_for_result(self, result): |
380 | 380 | pk = getattr(result, self.pk_attname) |
381 | 381 | return reverse('admin:%s_%s_change' % (self.opts.app_label, |
382 | | self.opts.module_name), |
| 382 | self.opts.model_name), |
383 | 383 | args=(quote(pk),), |
384 | 384 | current_app=self.model_admin.admin_site.name) |
-
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index a388774..4b79401 100644
a
|
b
|
class ForeignKeyRawIdWidget(forms.TextInput):
|
147 | 147 | # The related object is registered with the same AdminSite |
148 | 148 | related_url = reverse('admin:%s_%s_changelist' % |
149 | 149 | (rel_to._meta.app_label, |
150 | | rel_to._meta.module_name), |
| 150 | rel_to._meta.model_name), |
151 | 151 | current_app=self.admin_site.name) |
152 | 152 | |
153 | 153 | params = self.url_parameters() |
… |
… |
class RelatedFieldWidgetWrapper(forms.Widget):
|
247 | 247 | |
248 | 248 | def render(self, name, value, *args, **kwargs): |
249 | 249 | rel_to = self.rel.to |
250 | | info = (rel_to._meta.app_label, rel_to._meta.object_name.lower()) |
| 250 | info = (rel_to._meta.app_label, rel_to._meta.model_name) |
251 | 251 | self.widget.choices = self.choices |
252 | 252 | output = [self.widget.render(name, value, *args, **kwargs)] |
253 | 253 | if self.can_add_related: |
-
diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
index cb0c116..ef2790f 100644
a
|
b
|
def model_detail(request, app_label, model_name):
|
189 | 189 | raise Http404(_("App %r not found") % app_label) |
190 | 190 | model = None |
191 | 191 | for m in models.get_models(app_mod): |
192 | | if m._meta.object_name.lower() == model_name: |
| 192 | if m._meta.model_name == model_name: |
193 | 193 | model = m |
194 | 194 | break |
195 | 195 | if model is None: |
… |
… |
def model_detail(request, app_label, model_name):
|
224 | 224 | fields.append({ |
225 | 225 | 'name': "%s.all" % field.name, |
226 | 226 | "data_type": 'List', |
227 | | 'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name), |
| 227 | 'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name), |
228 | 228 | }) |
229 | 229 | fields.append({ |
230 | 230 | 'name' : "%s.count" % field.name, |
231 | 231 | 'data_type' : 'Integer', |
232 | | 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name), |
| 232 | 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name), |
233 | 233 | }) |
234 | 234 | |
235 | 235 | # Gather model methods. |
… |
… |
def model_detail(request, app_label, model_name):
|
243 | 243 | continue |
244 | 244 | verbose = func.__doc__ |
245 | 245 | if verbose: |
246 | | verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', _('model:') + opts.module_name) |
| 246 | verbose = utils.parse_rst(utils.trim_docstring(verbose), 'model', _('model:') + opts.model_name) |
247 | 247 | fields.append({ |
248 | 248 | 'name': func_name, |
249 | 249 | 'data_type': get_return_data_type(func_name), |
… |
… |
def model_detail(request, app_label, model_name):
|
257 | 257 | fields.append({ |
258 | 258 | 'name' : "%s.all" % accessor, |
259 | 259 | 'data_type' : 'List', |
260 | | 'verbose' : utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.module_name), |
| 260 | 'verbose' : utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name), |
261 | 261 | }) |
262 | 262 | fields.append({ |
263 | 263 | 'name' : "%s.count" % accessor, |
264 | 264 | 'data_type' : 'Integer', |
265 | | 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.module_name), |
| 265 | 'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name), |
266 | 266 | }) |
267 | 267 | return render_to_response('admin_doc/model_detail.html', { |
268 | 268 | 'root_path': urlresolvers.reverse('admin:index'), |
-
diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py
index 3d17fe2..b8ead73 100644
a
|
b
|
|
2 | 2 | # the template system can understand. |
3 | 3 | |
4 | 4 | class PermLookupDict(object): |
5 | | def __init__(self, user, module_name): |
6 | | self.user, self.module_name = user, module_name |
| 5 | def __init__(self, user, app_label): |
| 6 | self.user, self.app_label = user, app_label |
7 | 7 | |
8 | 8 | def __repr__(self): |
9 | 9 | return str(self.user.get_all_permissions()) |
10 | 10 | |
11 | 11 | def __getitem__(self, perm_name): |
12 | | return self.user.has_perm("%s.%s" % (self.module_name, perm_name)) |
| 12 | return self.user.has_perm("%s.%s" % (self.app_label, perm_name)) |
13 | 13 | |
14 | 14 | def __iter__(self): |
15 | 15 | # To fix 'item in perms.someapp' and __getitem__ iteraction we need to |
… |
… |
class PermLookupDict(object):
|
17 | 17 | raise TypeError("PermLookupDict is not iterable.") |
18 | 18 | |
19 | 19 | def __bool__(self): |
20 | | return self.user.has_module_perms(self.module_name) |
| 20 | return self.user.has_module_perms(self.app_label) |
21 | 21 | |
22 | 22 | def __nonzero__(self): # Python 2 compatibility |
23 | 23 | return type(self).__bool__(self) |
… |
… |
class PermWrapper(object):
|
27 | 27 | def __init__(self, user): |
28 | 28 | self.user = user |
29 | 29 | |
30 | | def __getitem__(self, module_name): |
31 | | return PermLookupDict(self.user, module_name) |
| 30 | def __getitem__(self, app_label): |
| 31 | return PermLookupDict(self.user, app_label) |
32 | 32 | |
33 | 33 | def __iter__(self): |
34 | 34 | # I am large, I contain multitudes. |
… |
… |
class PermWrapper(object):
|
41 | 41 | if '.' not in perm_name: |
42 | 42 | # The name refers to module. |
43 | 43 | return bool(self[perm_name]) |
44 | | module_name, perm_name = perm_name.split('.', 1) |
45 | | return self[module_name][perm_name] |
| 44 | app_label, perm_name = perm_name.split('.', 1) |
| 45 | return self[app_label][perm_name] |
46 | 46 | |
47 | 47 | |
48 | 48 | def auth(request): |
-
diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index a77bba0..475dd25 100644
a
|
b
|
from django.utils.six.moves import input
|
17 | 17 | |
18 | 18 | |
19 | 19 | def _get_permission_codename(action, opts): |
20 | | return '%s_%s' % (action, opts.object_name.lower()) |
| 20 | return '%s_%s' % (action, opts.model_name) |
21 | 21 | |
22 | 22 | |
23 | 23 | def _get_all_permissions(opts, ctype): |
-
diff --git a/django/contrib/comments/moderation.py b/django/contrib/comments/moderation.py
index 6c56d7a..6648aeb 100644
a
|
b
|
class Moderator(object):
|
302 | 302 | model_or_iterable = [model_or_iterable] |
303 | 303 | for model in model_or_iterable: |
304 | 304 | if model in self._registry: |
305 | | raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.module_name) |
| 305 | raise AlreadyModerated("The model '%s' is already being moderated" % model._meta.model_name) |
306 | 306 | self._registry[model] = moderation_class(model) |
307 | 307 | |
308 | 308 | def unregister(self, model_or_iterable): |
… |
… |
class Moderator(object):
|
318 | 318 | model_or_iterable = [model_or_iterable] |
319 | 319 | for model in model_or_iterable: |
320 | 320 | if model not in self._registry: |
321 | | raise NotModerated("The model '%s' is not currently being moderated" % model._meta.module_name) |
| 321 | raise NotModerated("The model '%s' is not currently being moderated" % model._meta.model_name) |
322 | 322 | del self._registry[model] |
323 | 323 | |
324 | 324 | 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 7c02b21..befd326 100644
a
|
b
|
def post_comment(request, next=None, using=None):
|
86 | 86 | # These first two exist for purely historical reasons. |
87 | 87 | # Django v1.0 and v1.1 allowed the underscore format for |
88 | 88 | # preview templates, so we have to preserve that format. |
89 | | "comments/%s_%s_preview.html" % (model._meta.app_label, model._meta.module_name), |
| 89 | "comments/%s_%s_preview.html" % (model._meta.app_label, model._meta.model_name), |
90 | 90 | "comments/%s_preview.html" % model._meta.app_label, |
91 | 91 | # Now the usual directory based template hierarchy. |
92 | | "comments/%s/%s/preview.html" % (model._meta.app_label, model._meta.module_name), |
| 92 | "comments/%s/%s/preview.html" % (model._meta.app_label, model._meta.model_name), |
93 | 93 | "comments/%s/preview.html" % model._meta.app_label, |
94 | 94 | "comments/preview.html", |
95 | 95 | ] |
-
diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
index cda4d46..d849d16 100644
a
|
b
|
class BaseGenericInlineFormSet(BaseModelFormSet):
|
389 | 389 | opts = self.model._meta |
390 | 390 | self.instance = instance |
391 | 391 | self.rel_name = '-'.join(( |
392 | | opts.app_label, opts.object_name.lower(), |
| 392 | opts.app_label, opts.model_name, |
393 | 393 | self.ct_field.name, self.ct_fk_field.name, |
394 | 394 | )) |
395 | 395 | if self.instance is None or self.instance.pk is None: |
… |
… |
class BaseGenericInlineFormSet(BaseModelFormSet):
|
409 | 409 | @classmethod |
410 | 410 | def get_default_prefix(cls): |
411 | 411 | opts = cls.model._meta |
412 | | return '-'.join((opts.app_label, opts.object_name.lower(), |
| 412 | return '-'.join((opts.app_label, opts.model_name, |
413 | 413 | cls.ct_field.name, cls.ct_fk_field.name, |
414 | 414 | )) |
415 | 415 | |
-
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
index 8329ab6..ddd7654 100644
a
|
b
|
def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, *
|
21 | 21 | # They all have the same app_label, get the first one. |
22 | 22 | app_label = app_models[0]._meta.app_label |
23 | 23 | app_models = dict( |
24 | | (model._meta.object_name.lower(), model) |
| 24 | (model._meta.model_name, model) |
25 | 25 | for model in app_models |
26 | 26 | ) |
27 | 27 | |
-
diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
index b658655..f0bd109 100644
a
|
b
|
class ContentTypeManager(models.Manager):
|
25 | 25 | return model._meta |
26 | 26 | |
27 | 27 | def _get_from_cache(self, opts): |
28 | | key = (opts.app_label, opts.object_name.lower()) |
| 28 | key = (opts.app_label, opts.model_name) |
29 | 29 | return self.__class__._cache[self.db][key] |
30 | 30 | |
31 | 31 | def get_for_model(self, model, for_concrete_model=True): |
… |
… |
class ContentTypeManager(models.Manager):
|
43 | 43 | # django.utils.functional.__proxy__ object. |
44 | 44 | ct, created = self.get_or_create( |
45 | 45 | app_label = opts.app_label, |
46 | | model = opts.object_name.lower(), |
| 46 | model = opts.model_name, |
47 | 47 | defaults = {'name': smart_text(opts.verbose_name_raw)}, |
48 | 48 | ) |
49 | 49 | self._add_to_cache(self.db, ct) |
… |
… |
class ContentTypeManager(models.Manager):
|
67 | 67 | ct = self._get_from_cache(opts) |
68 | 68 | except KeyError: |
69 | 69 | needed_app_labels.add(opts.app_label) |
70 | | needed_models.add(opts.object_name.lower()) |
| 70 | needed_models.add(opts.model_name) |
71 | 71 | needed_opts.add(opts) |
72 | 72 | else: |
73 | 73 | results[model] = ct |
… |
… |
class ContentTypeManager(models.Manager):
|
86 | 86 | # These weren't in the cache, or the DB, create them. |
87 | 87 | ct = self.create( |
88 | 88 | app_label=opts.app_label, |
89 | | model=opts.object_name.lower(), |
| 89 | model=opts.model_name, |
90 | 90 | name=smart_text(opts.verbose_name_raw), |
91 | 91 | ) |
92 | 92 | self._add_to_cache(self.db, ct) |
… |
… |
class ContentTypeManager(models.Manager):
|
119 | 119 | def _add_to_cache(self, using, ct): |
120 | 120 | """Insert a ContentType into the cache.""" |
121 | 121 | model = ct.model_class() |
122 | | key = (model._meta.app_label, model._meta.object_name.lower()) |
| 122 | key = (model._meta.app_label, model._meta.model_name) |
123 | 123 | self.__class__._cache.setdefault(using, {})[key] = ct |
124 | 124 | self.__class__._cache.setdefault(using, {})[ct.id] = ct |
125 | 125 | |
-
diff --git a/django/contrib/gis/sitemaps/kml.py b/django/contrib/gis/sitemaps/kml.py
index db30606..837fe62 100644
a
|
b
|
class KMLSitemap(Sitemap):
|
30 | 30 | for field in source._meta.fields: |
31 | 31 | if isinstance(field, GeometryField): |
32 | 32 | kml_sources.append((source._meta.app_label, |
33 | | source._meta.module_name, |
| 33 | source._meta.model_name, |
34 | 34 | field.name)) |
35 | 35 | elif isinstance(source, (list, tuple)): |
36 | 36 | if len(source) != 3: |
-
diff --git a/django/core/cache/backends/db.py b/django/core/cache/backends/db.py
index c93bc90..5c9ea3e 100644
a
|
b
|
class Options(object):
|
23 | 23 | def __init__(self, table): |
24 | 24 | self.db_table = table |
25 | 25 | self.app_label = 'django_cache' |
26 | | self.module_name = 'cacheentry' |
| 26 | self.model_name = 'cacheentry' |
27 | 27 | self.verbose_name = 'cache entry' |
28 | 28 | self.verbose_name_plural = 'cache entries' |
29 | 29 | self.object_name = 'CacheEntry' |
-
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index e46f4ae..66df43e 100644
a
|
b
|
def custom_sql_for_model(model, style, connection):
|
173 | 173 | |
174 | 174 | # Find custom SQL, if it's available. |
175 | 175 | backend_name = connection.settings_dict['ENGINE'].split('.')[-1] |
176 | | sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)), |
177 | | os.path.join(app_dir, "%s.sql" % opts.object_name.lower())] |
| 176 | sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.model_name, backend_name)), |
| 177 | os.path.join(app_dir, "%s.sql" % opts.model_name)] |
178 | 178 | for sql_file in sql_files: |
179 | 179 | if os.path.exists(sql_file): |
180 | 180 | 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 37fa906..5e07e2a 100644
a
|
b
|
def Deserializer(object_list, **options):
|
143 | 143 | |
144 | 144 | def _get_model(model_identifier): |
145 | 145 | """ |
146 | | Helper to look up a model from an "app_label.module_name" string. |
| 146 | Helper to look up a model from an "app_label.model_name" string. |
147 | 147 | """ |
148 | 148 | try: |
149 | 149 | Model = models.get_model(*model_identifier.split(".")) |
-
diff --git a/django/core/xheaders.py b/django/core/xheaders.py
index b650a3a..3766628 100644
a
|
b
|
def populate_xheaders(request, response, model, object_id):
|
20 | 20 | if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS |
21 | 21 | or (hasattr(request, 'user') and request.user.is_active |
22 | 22 | and request.user.is_staff)): |
23 | | response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.object_name.lower()) |
| 23 | response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.model_name) |
24 | 24 | response['X-Object-Id'] = str(object_id) |
-
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 38afc60..5f05865 100644
a
|
b
|
class ModelBase(type):
|
191 | 191 | if base in o2o_map: |
192 | 192 | field = o2o_map[base] |
193 | 193 | elif not is_proxy: |
194 | | attr_name = '%s_ptr' % base._meta.module_name |
| 194 | attr_name = '%s_ptr' % base._meta.model_name |
195 | 195 | field = OneToOneField(base, name=attr_name, |
196 | 196 | auto_created=True, parent_link=True) |
197 | 197 | new_class.add_to_class(attr_name, field) |
… |
… |
def method_get_order(ordered_obj, self):
|
973 | 973 | ############################################## |
974 | 974 | |
975 | 975 | def get_absolute_url(opts, func, self, *args, **kwargs): |
976 | | return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs) |
| 976 | return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.model_name), func)(self, *args, **kwargs) |
977 | 977 | |
978 | 978 | |
979 | 979 | ######## |
-
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index ae792a3..bd2e288 100644
a
|
b
|
class RelatedField(object):
|
118 | 118 | self.do_related_class(other, cls) |
119 | 119 | |
120 | 120 | def set_attributes_from_rel(self): |
121 | | self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name) |
| 121 | self.name = self.name or (self.rel.to._meta.model_name + '_' + self.rel.to._meta.pk.name) |
122 | 122 | if self.verbose_name is None: |
123 | 123 | self.verbose_name = self.rel.to._meta.verbose_name |
124 | 124 | self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.name |
… |
… |
class RelatedField(object):
|
222 | 222 | # related object in a table-spanning query. It uses the lower-cased |
223 | 223 | # object_name by default, but this can be overridden with the |
224 | 224 | # "related_name" option. |
225 | | return self.rel.related_name or self.opts.object_name.lower() |
| 225 | return self.rel.related_name or self.opts.model_name |
226 | 226 | |
227 | 227 | |
228 | 228 | class SingleRelatedObjectDescriptor(object): |
… |
… |
class ForeignKey(RelatedField, Field):
|
983 | 983 | |
984 | 984 | def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs): |
985 | 985 | try: |
986 | | to_name = to._meta.object_name.lower() |
| 986 | to_name = to._meta.model_name |
987 | 987 | except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT |
988 | 988 | 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) |
989 | 989 | else: |
… |
… |
def create_many_to_many_intermediary_model(field, klass):
|
1174 | 1174 | from_ = 'from_%s' % to.lower() |
1175 | 1175 | to = 'to_%s' % to.lower() |
1176 | 1176 | else: |
1177 | | from_ = klass._meta.object_name.lower() |
| 1177 | from_ = klass._meta.model_name |
1178 | 1178 | to = to.lower() |
1179 | 1179 | meta = type('Meta', (object,), { |
1180 | 1180 | 'db_table': field._get_m2m_db_table(klass._meta), |
-
diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index 56edc36..c027105 100644
a
|
b
|
class AppCache(object):
|
239 | 239 | for model in models: |
240 | 240 | # Store as 'name: model' pair in a dictionary |
241 | 241 | # in the app_models dictionary |
242 | | model_name = model._meta.object_name.lower() |
| 242 | model_name = model._meta.model_name |
243 | 243 | model_dict = self.app_models.setdefault(app_label, SortedDict()) |
244 | 244 | if model_name in model_dict: |
245 | 245 | # 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 952596b..a302e2d 100644
a
|
b
|
from __future__ import unicode_literals
|
2 | 2 | |
3 | 3 | import re |
4 | 4 | from bisect import bisect |
| 5 | import warnings |
5 | 6 | |
6 | 7 | from django.conf import settings |
7 | 8 | from django.db.models.fields.related import ManyToManyRel |
… |
… |
class Options(object):
|
28 | 29 | def __init__(self, meta, app_label=None): |
29 | 30 | self.local_fields, self.local_many_to_many = [], [] |
30 | 31 | self.virtual_fields = [] |
31 | | self.module_name, self.verbose_name = None, None |
| 32 | self.model_name, self.verbose_name = None, None |
32 | 33 | self.verbose_name_plural = None |
33 | 34 | self.db_table = '' |
34 | 35 | self.ordering = [] |
… |
… |
class Options(object):
|
78 | 79 | self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS |
79 | 80 | # First, construct the default values for these options. |
80 | 81 | self.object_name = cls.__name__ |
81 | | self.module_name = self.object_name.lower() |
| 82 | self.model_name = self.object_name.lower() |
82 | 83 | self.verbose_name = get_verbose_name(self.object_name) |
83 | 84 | |
84 | 85 | # Next, apply any overridden values from 'class Meta'. |
… |
… |
class Options(object):
|
116 | 117 | self.verbose_name_plural = string_concat(self.verbose_name, 's') |
117 | 118 | del self.meta |
118 | 119 | |
119 | | # If the db_table wasn't provided, use the app_label + module_name. |
| 120 | # If the db_table wasn't provided, use the app_label + model_name. |
120 | 121 | if not self.db_table: |
121 | | self.db_table = "%s_%s" % (self.app_label, self.module_name) |
| 122 | self.db_table = "%s_%s" % (self.app_label, self.model_name) |
122 | 123 | self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) |
123 | 124 | |
| 125 | @property |
| 126 | def module_name(self): |
| 127 | """ |
| 128 | This property has been deprecated in favor of `model_name`. refs #19689 |
| 129 | """ |
| 130 | warnings.warn( |
| 131 | "Options.module_name has been deprecated in favor of model_name", |
| 132 | PendingDeprecationWarning, stacklevel=2) |
| 133 | return self.model_name |
| 134 | |
124 | 135 | def _prepare(self, model): |
125 | 136 | if self.order_with_respect_to: |
126 | 137 | self.order_with_respect_to = self.get_field(self.order_with_respect_to) |
… |
… |
class Options(object):
|
193 | 204 | return '<Options for %s>' % self.object_name |
194 | 205 | |
195 | 206 | def __str__(self): |
196 | | return "%s.%s" % (smart_text(self.app_label), smart_text(self.module_name)) |
| 207 | return "%s.%s" % (smart_text(self.app_label), smart_text(self.model_name)) |
197 | 208 | |
198 | 209 | def verbose_name_raw(self): |
199 | 210 | """ |
… |
… |
class Options(object):
|
217 | 228 | case insensitive, so we make sure we are case insensitive here. |
218 | 229 | """ |
219 | 230 | if self.swappable: |
220 | | model_label = '%s.%s' % (self.app_label, self.object_name.lower()) |
| 231 | model_label = '%s.%s' % (self.app_label, self.model_name) |
221 | 232 | swapped_for = getattr(settings, self.swappable, None) |
222 | 233 | if swapped_for: |
223 | 234 | try: |
… |
… |
class Options(object):
|
371 | 382 | return cache |
372 | 383 | |
373 | 384 | def get_add_permission(self): |
374 | | return 'add_%s' % self.object_name.lower() |
| 385 | return 'add_%s' % self.model_name |
375 | 386 | |
376 | 387 | def get_change_permission(self): |
377 | | return 'change_%s' % self.object_name.lower() |
| 388 | return 'change_%s' % self.model_name |
378 | 389 | |
379 | 390 | def get_delete_permission(self): |
380 | | return 'delete_%s' % self.object_name.lower() |
| 391 | return 'delete_%s' % self.model_name |
381 | 392 | |
382 | 393 | def get_all_related_objects(self, local_only=False, include_hidden=False, |
383 | 394 | include_proxy_eq=False): |
-
diff --git a/django/db/models/related.py b/django/db/models/related.py
index 2693213..53645be 100644
a
|
b
|
class RelatedObject(object):
|
16 | 16 | self.model = model |
17 | 17 | self.opts = model._meta |
18 | 18 | self.field = field |
19 | | self.name = '%s:%s' % (self.opts.app_label, self.opts.module_name) |
20 | | self.var_name = self.opts.object_name.lower() |
| 19 | self.name = '%s:%s' % (self.opts.app_label, self.opts.model_name) |
| 20 | self.var_name = self.opts.model_name |
21 | 21 | |
22 | 22 | def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, |
23 | 23 | limit_to_currently_related=False): |
… |
… |
class RelatedObject(object):
|
31 | 31 | queryset = self.model._default_manager.all() |
32 | 32 | if limit_to_currently_related: |
33 | 33 | queryset = queryset.complex_filter( |
34 | | {'%s__isnull' % self.parent_model._meta.module_name: False}) |
| 34 | {'%s__isnull' % self.parent_model._meta.model_name: False}) |
35 | 35 | lst = [(x._get_pk_val(), smart_text(x)) for x in queryset] |
36 | 36 | return first_choice + lst |
37 | 37 | |
… |
… |
class RelatedObject(object):
|
56 | 56 | # If this is a symmetrical m2m relation on self, there is no reverse accessor. |
57 | 57 | if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model: |
58 | 58 | return None |
59 | | return self.field.rel.related_name or (self.opts.object_name.lower() + '_set') |
| 59 | return self.field.rel.related_name or (self.opts.model_name + '_set') |
60 | 60 | else: |
61 | | return self.field.rel.related_name or (self.opts.object_name.lower()) |
| 61 | return self.field.rel.related_name or (self.opts.model_name) |
62 | 62 | |
63 | 63 | def get_cache_name(self): |
64 | 64 | return "_%s_cache" % self.get_accessor_name() |
-
diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py
index c27b92b..58302bb 100644
a
|
b
|
class SingleObjectMixin(ContextMixin):
|
84 | 84 | if self.context_object_name: |
85 | 85 | return self.context_object_name |
86 | 86 | elif isinstance(obj, models.Model): |
87 | | return obj._meta.object_name.lower() |
| 87 | return obj._meta.model_name |
88 | 88 | else: |
89 | 89 | return None |
90 | 90 | |
… |
… |
class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
|
144 | 144 | if isinstance(self.object, models.Model): |
145 | 145 | names.append("%s/%s%s.html" % ( |
146 | 146 | self.object._meta.app_label, |
147 | | self.object._meta.object_name.lower(), |
| 147 | self.object._meta.model_name, |
148 | 148 | self.template_name_suffix |
149 | 149 | )) |
150 | 150 | elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model): |
151 | 151 | names.append("%s/%s%s.html" % ( |
152 | 152 | self.model._meta.app_label, |
153 | | self.model._meta.object_name.lower(), |
| 153 | self.model._meta.model_name, |
154 | 154 | self.template_name_suffix |
155 | 155 | )) |
156 | 156 | return names |
-
diff --git a/django/views/generic/list.py b/django/views/generic/list.py
index 1f28616..08c4bbc 100644
a
|
b
|
class MultipleObjectMixin(ContextMixin):
|
97 | 97 | if self.context_object_name: |
98 | 98 | return self.context_object_name |
99 | 99 | elif hasattr(object_list, 'model'): |
100 | | return '%s_list' % object_list.model._meta.object_name.lower() |
| 100 | return '%s_list' % object_list.model._meta.model_name |
101 | 101 | else: |
102 | 102 | return None |
103 | 103 | |
… |
… |
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
177 | 177 | # generated ones. |
178 | 178 | if hasattr(self.object_list, 'model'): |
179 | 179 | opts = self.object_list.model._meta |
180 | | names.append("%s/%s%s.html" % (opts.app_label, opts.object_name.lower(), self.template_name_suffix)) |
| 180 | names.append("%s/%s%s.html" % (opts.app_label, opts.model_name, self.template_name_suffix)) |
181 | 181 | |
182 | 182 | return names |
183 | 183 | |
-
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
index df3d84f..099951d 100644
a
|
b
|
these changes.
|
327 | 327 | :class:`django.middleware.common.BrokenLinkEmailsMiddleware` middleware to |
328 | 328 | your :setting:`MIDDLEWARE_CLASSES` setting instead. |
329 | 329 | |
| 330 | * The undocumented ``module_name`` model meta attribute was renamed to |
| 331 | ``model_name`` in 1.6. The backward compatibility will be removed -- |
| 332 | ``Model._meta.module_name`` will no longer work. |
| 333 | |
330 | 334 | 2.0 |
331 | 335 | --- |
332 | 336 | |
-
diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt
index 32e5172..d5b0d4a 100644
a
|
b
|
from your settings.
|
127 | 127 | |
128 | 128 | If you defined your own form widgets and defined the ``_has_changed`` method |
129 | 129 | on a widget, you should now define this method on the form field itself. |
| 130 | |
| 131 | ``module_name`` model meta attribute |
| 132 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 133 | |
| 134 | This undocumented and meaningless ``module_name`` attribute of |
| 135 | ``django.db.models.options.Options`` was renamed to ``model_name``. |
| 136 | No newline at end of file |
-
diff --git a/tests/regressiontests/admin_custom_urls/models.py b/tests/regressiontests/admin_custom_urls/models.py
index ef04c2a..55fc064 100644
a
|
b
|
class ActionAdmin(admin.ModelAdmin):
|
42 | 42 | return self.admin_site.admin_view(view)(*args, **kwargs) |
43 | 43 | return update_wrapper(wrapper, view) |
44 | 44 | |
45 | | info = self.model._meta.app_label, self.model._meta.module_name |
| 45 | info = self.model._meta.app_label, self.model._meta.model_name |
46 | 46 | |
47 | 47 | view_name = '%s_%s_add' % info |
48 | 48 | |