diff --git a/django/contrib/databrowse/sites.py b/django/contrib/databrowse/sites.py index 172ca5271e..d90bb562b2 100644 --- a/django/contrib/databrowse/sites.py +++ b/django/contrib/databrowse/sites.py @@ -73,7 +73,7 @@ class DatabrowseSite(object): self.registry = {} # model_class -> databrowse_class self.root_url = None - def register(self, model_or_iterable, databrowse_class=None, **options): + def register(self, *model_list, **options): """ Registers the given model(s) with the given databrowse site. @@ -84,23 +84,19 @@ class DatabrowseSite(object): If a model is already registered, this will raise AlreadyRegistered. """ - databrowse_class = databrowse_class or DefaultModelDatabrowse - if issubclass(model_or_iterable, models.Model): - model_or_iterable = [model_or_iterable] - for model in model_or_iterable: + databrowse_class = options.pop('databrowse_class', DefaultModelDatabrowse) + for model in model_list: if model in self.registry: raise AlreadyRegistered('The model %s is already registered' % model.__name__) self.registry[model] = databrowse_class - def unregister(self, model_or_iterable): + def unregister(self, *model_list): """ Unregisters the given model(s). If a model isn't already registered, this will raise NotRegistered. """ - if issubclass(model_or_iterable, models.Model): - model_or_iterable = [model_or_iterable] - for model in model_or_iterable: + for model in model_list: if model not in self.registry: raise NotRegistered('The model %s is not registered' % model.__name__) del self.registry[model] diff --git a/docs/ref/contrib/databrowse.txt b/docs/ref/contrib/databrowse.txt index f8fedc4482..3d411bb7b4 100644 --- a/docs/ref/contrib/databrowse.txt +++ b/docs/ref/contrib/databrowse.txt @@ -33,13 +33,18 @@ How to use Databrowse 2. Register a number of models with the Databrowse site:: from django.contrib import databrowse - from myapp.models import SomeModel, SomeOtherModel + from myapp.models import SomeModel, SomeOtherModel, YetAnotherModel databrowse.site.register(SomeModel) - databrowse.site.register(SomeOtherModel) + databrowse.site.register(SomeOtherModel, YetAnotherModel) Note that you should register the model *classes*, not instances. + .. versionchanged:: 1.4 + + Since Django 1.4, it is possible to register several models in the same + call to :func:`~databrowse.site.register`. + It doesn't matter where you put this, as long as it gets executed at some point. A good place for it is in your :doc:`URLconf file ` (``urls.py``). diff --git a/tests/runtests.py b/tests/runtests.py index ed032a57d0..944c6aa82e 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -4,9 +4,13 @@ import shutil import subprocess import sys import tempfile +import warnings from django import contrib +# databrowse is deprecated, but we still want to run its tests +warnings.filterwarnings('ignore', "The Databrowse contrib app is deprecated", + PendingDeprecationWarning, 'django.contrib.databrowse') CONTRIB_DIR_NAME = 'django.contrib' MODEL_TESTS_DIR_NAME = 'modeltests' @@ -34,6 +38,7 @@ ALWAYS_INSTALLED_APPS = [ 'django.contrib.comments', 'django.contrib.admin', 'django.contrib.admindocs', + 'django.contrib.databrowse', 'django.contrib.staticfiles', 'django.contrib.humanize', 'regressiontests.staticfiles_tests',