mirror of https://github.com/django/django.git
Used AdminSite.is_registered() where appropriate.
This commit is contained in:
parent
966ecdd482
commit
95cdf9dc66
|
@ -120,7 +120,7 @@ class AdminSite:
|
|||
% model.__name__
|
||||
)
|
||||
|
||||
if model in self._registry:
|
||||
if self.is_registered(model):
|
||||
registered_admin = str(self._registry[model])
|
||||
msg = "The model %s is already registered " % model.__name__
|
||||
if registered_admin.endswith(".ModelAdmin"):
|
||||
|
@ -156,7 +156,7 @@ class AdminSite:
|
|||
if isinstance(model_or_iterable, ModelBase):
|
||||
model_or_iterable = [model_or_iterable]
|
||||
for model in model_or_iterable:
|
||||
if model not in self._registry:
|
||||
if not self.is_registered(model):
|
||||
raise NotRegistered("The model %s is not registered" % model.__name__)
|
||||
del self._registry[model]
|
||||
|
||||
|
|
|
@ -139,12 +139,11 @@ def get_deleted_objects(objs, request, admin_site):
|
|||
|
||||
def format_callback(obj):
|
||||
model = obj.__class__
|
||||
has_admin = model in admin_site._registry
|
||||
opts = obj._meta
|
||||
|
||||
no_edit_link = "%s: %s" % (capfirst(opts.verbose_name), obj)
|
||||
|
||||
if has_admin:
|
||||
if admin_site.is_registered(model):
|
||||
if not admin_site._registry[model].has_delete_permission(request, obj):
|
||||
perms_needed.add(opts.verbose_name)
|
||||
try:
|
||||
|
|
|
@ -145,7 +145,7 @@ class ForeignKeyRawIdWidget(forms.TextInput):
|
|||
def get_context(self, name, value, attrs):
|
||||
context = super().get_context(name, value, attrs)
|
||||
rel_to = self.rel.model
|
||||
if rel_to in self.admin_site._registry:
|
||||
if self.admin_site.is_registered(rel_to):
|
||||
# The related object is registered with the same AdminSite
|
||||
related_url = reverse(
|
||||
"admin:%s_%s_changelist"
|
||||
|
@ -222,7 +222,7 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
|
|||
|
||||
def get_context(self, name, value, attrs):
|
||||
context = super().get_context(name, value, attrs)
|
||||
if self.rel.model in self.admin_site._registry:
|
||||
if self.admin_site.is_registered(self.rel.model):
|
||||
# The related object is registered with the same AdminSite
|
||||
context["widget"]["attrs"]["class"] = "vManyToManyRawIdAdminField"
|
||||
return context
|
||||
|
@ -268,7 +268,7 @@ class RelatedFieldWidgetWrapper(forms.Widget):
|
|||
# Backwards compatible check for whether a user can add related
|
||||
# objects.
|
||||
if can_add_related is None:
|
||||
can_add_related = rel.model in admin_site._registry
|
||||
can_add_related = admin_site.is_registered(rel.model)
|
||||
self.can_add_related = can_add_related
|
||||
# XXX: The UX does not support multiple selected values.
|
||||
multiple = getattr(widget, "allow_multiple_selected", False)
|
||||
|
|
|
@ -148,7 +148,7 @@ class TestRelatedFieldsAdminOrdering(TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
site.unregister(Song)
|
||||
if Band in site._registry:
|
||||
if site.is_registered(Band):
|
||||
site.unregister(Band)
|
||||
|
||||
def check_ordering_of_field_choices(self, correct_ordering):
|
||||
|
|
Loading…
Reference in New Issue