diff options
| author | a1tus <mortas.11@gmail.com> | 2014-10-21 01:29:28 +0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-10-23 09:49:24 -0400 |
| commit | 2d75515a4c4fe726e26ebb1a2d2acbc9d047cba6 (patch) | |
| tree | fb0380ada5e989356d64f27cfe3ab84ac72686e1 /django | |
| parent | 70428902c0c4d7660118b935241b54c17f662802 (diff) | |
Fixed #23444 -- Deprecated django.contrib.admin.helpers.InlineAdminForm.original_content_type_id
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/helpers.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index 0df678f566..a7c95f5046 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +import warnings + from django import forms from django.contrib.admin.utils import (flatten_fieldsets, lookup_field, display_for_field, label_for_field, help_text_for_field) @@ -8,7 +10,9 @@ from django.core.exceptions import ObjectDoesNotExist from django.db.models.fields.related import ManyToManyRel from django.forms.utils import flatatt from django.template.defaultfilters import capfirst, linebreaksbr +from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_text, smart_text +from django.utils.functional import cached_property from django.utils.html import conditional_escape, format_html from django.utils.safestring import mark_safe from django.utils import six @@ -270,16 +274,26 @@ class InlineAdminForm(AdminForm): self.formset = formset self.model_admin = model_admin self.original = original - if original is not None: - # Since this module gets imported in the application's root package, - # it cannot import models from other applications at the module level. - from django.contrib.contenttypes.models import ContentType - self.original_content_type_id = ContentType.objects.get_for_model(original).pk self.show_url = original and view_on_site_url is not None self.absolute_url = view_on_site_url super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields, readonly_fields, model_admin) + @cached_property + def original_content_type_id(self): + warnings.warn( + 'InlineAdminForm.original_content_type_id is deprecated and will be ' + 'removed in Django 2.0. If you were using this attribute to construct ' + 'the "view on site" URL, use the `absolute_url` attribute instead.', + RemovedInDjango20Warning, stacklevel=2 + ) + if self.original is not None: + # Since this module gets imported in the application's root package, + # it cannot import models from other applications at the module level. + from django.contrib.contenttypes.models import ContentType + return ContentType.objects.get_for_model(self.original).pk + raise AttributeError + def __iter__(self): for name, options in self.fieldsets: yield InlineFieldset(self.formset, self.form, name, |
