diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index b516507..d4ad94f 100644
|
a
|
b
|
import unicodedata
|
| 7 | 7 | from django.contrib.auth import models as auth_app |
| 8 | 8 | from django.db.models import get_models, signals |
| 9 | 9 | from django.contrib.auth.models import User |
| | 10 | from django.db import DEFAULT_DB_ALIAS |
| 10 | 11 | |
| 11 | 12 | |
| 12 | 13 | def _get_permission_codename(action, opts): |
| … |
… |
def _get_all_permissions(opts):
|
| 21 | 22 | return perms + list(opts.permissions) |
| 22 | 23 | |
| 23 | 24 | |
| 24 | | def create_permissions(app, created_models, verbosity, **kwargs): |
| | 25 | def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kwargs): |
| 25 | 26 | from django.contrib.contenttypes.models import ContentType |
| 26 | 27 | |
| 27 | 28 | app_models = get_models(app) |
| … |
… |
def create_permissions(app, created_models, verbosity, **kwargs):
|
| 32 | 33 | # The codenames and ctypes that should exist. |
| 33 | 34 | ctypes = set() |
| 34 | 35 | for klass in app_models: |
| 35 | | ctype = ContentType.objects.get_for_model(klass) |
| | 36 | ctype = ContentType.objects.db_manager(db).get_for_model(klass) |
| 36 | 37 | ctypes.add(ctype) |
| 37 | 38 | for perm in _get_all_permissions(klass._meta): |
| 38 | 39 | searched_perms.append((ctype, perm)) |
| … |
… |
def create_permissions(app, created_models, verbosity, **kwargs):
|
| 40 | 41 | # Find all the Permissions that have a context_type for a model we're |
| 41 | 42 | # looking for. We don't need to check for codenames since we already have |
| 42 | 43 | # a list of the ones we're going to create. |
| 43 | | all_perms = set(auth_app.Permission.objects.filter( |
| | 44 | all_perms = set(auth_app.Permission.objects.using(db).filter( |
| 44 | 45 | content_type__in=ctypes, |
| 45 | 46 | ).values_list( |
| 46 | 47 | "content_type", "codename" |
| … |
… |
def create_permissions(app, created_models, verbosity, **kwargs):
|
| 51 | 52 | for ctype, (codename, name) in searched_perms |
| 52 | 53 | if (ctype.pk, codename) not in all_perms |
| 53 | 54 | ] |
| 54 | | auth_app.Permission.objects.bulk_create(objs) |
| | 55 | auth_app.Permission.objects.using(db).bulk_create(objs) |
| 55 | 56 | if verbosity >= 2: |
| 56 | 57 | for obj in objs: |
| 57 | 58 | print "Adding permission '%s'" % obj |
diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
index d47d557..cb46654 100644
|
a
|
b
|
|
| 1 | 1 | from django.contrib.contenttypes.models import ContentType |
| 2 | 2 | from django.db.models import get_apps, get_models, signals |
| 3 | 3 | from django.utils.encoding import smart_unicode |
| | 4 | from django.db import DEFAULT_DB_ALIAS |
| 4 | 5 | |
| 5 | | def update_contenttypes(app, created_models, verbosity=2, **kwargs): |
| | 6 | def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, **kwargs): |
| 6 | 7 | """ |
| 7 | 8 | Creates content types for models in the given app, removing any model |
| 8 | 9 | entries that no longer have a matching model class. |
| … |
… |
def update_contenttypes(app, created_models, verbosity=2, **kwargs):
|
| 20 | 21 | # Get all the content types |
| 21 | 22 | content_types = dict( |
| 22 | 23 | (ct.model, ct) |
| 23 | | for ct in ContentType.objects.filter(app_label=app_label) |
| | 24 | for ct in ContentType.objects.using(db).filter(app_label=app_label) |
| 24 | 25 | ) |
| 25 | 26 | to_remove = [ |
| 26 | 27 | ct |
| … |
… |
def update_contenttypes(app, created_models, verbosity=2, **kwargs):
|
| 28 | 29 | if model_name not in app_models |
| 29 | 30 | ] |
| 30 | 31 | |
| 31 | | cts = ContentType.objects.bulk_create([ |
| | 32 | cts = ContentType.objects.using(db).bulk_create([ |
| 32 | 33 | ContentType( |
| 33 | 34 | name=smart_unicode(model._meta.verbose_name_raw), |
| 34 | 35 | app_label=app_label, |