Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #5968 -- Allowed (un-)registering with databrowse several model…

…s at once.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17405 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1cc800783c0f02a8f65e85b53ecb05ae5c0a4d88 1 parent 4a3acee
@aaugustin aaugustin authored
View
14 django/contrib/databrowse/sites.py
@@ -73,7 +73,7 @@ def __init__(self):
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 @@ def register(self, model_or_iterable, databrowse_class=None, **options):
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]
View
9 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
</topics/http/urls>` (``urls.py``).
View
5 tests/runtests.py
@@ -4,9 +4,13 @@
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 @@
'django.contrib.comments',
'django.contrib.admin',
'django.contrib.admindocs',
+ 'django.contrib.databrowse',
'django.contrib.staticfiles',
'django.contrib.humanize',
'regressiontests.staticfiles_tests',
Please sign in to comment.
Something went wrong with that request. Please try again.