Ticket #15610: django_contenttypes.patch

File django_contenttypes.patch, 1015 bytes (added by natalie.stepina@…, 14 years ago)

Django 1.2.1 patch for ContentType multi-db support

  • django/contrib/contenttypes/models.py

     
    11from django.db import models
    22from django.utils.translation import ugettext_lazy as _
    33from django.utils.encoding import smart_unicode
     4from django.db import router, DEFAULT_DB_ALIAS
    45
     6
    57class ContentTypeManager(models.Manager):
    68
    79    # Cache to avoid re-looking up ContentType objects all over the place.
     
    99101        method. The ObjectNotExist exception, if thrown, will not be caught,
    100102        so code that calls this method should catch it.
    101103        """
    102         return self.model_class()._default_manager.using(self._state.db).get(**kwargs)
     104        return self.model_class()._default_manager.using(router.db_for_read(self.model_class()) or DEFAULT_DB_ALIAS).get(**kwargs)
    103105
    104106    def natural_key(self):
    105107        return (self.app_label, self.model)
Back to Top