Ticket #15610: django-1.6.5-15610.patch

File django-1.6.5-15610.patch, 1.9 KB (added by 4glitch@…, 10 years ago)

The same approach for 1.6.5

  • django/contrib/contenttypes/generic.py

    a b  
    6565
    6666    def get_content_type(self, obj=None, id=None, using=None):
    6767        if obj is not None:
    68             return ContentType.objects.db_manager(obj._state.db).get_for_model(
     68            return ContentType.objects.db_manager(
     69                ContentType.objects.db).get_for_model(
    6970                obj, for_concrete_model=self.for_concrete_model)
    7071        elif id:
    7172            return ContentType.objects.db_manager(using).get_for_id(id)
  • django/contrib/contenttypes/models.py

    a b  
    11from django.db import models
     2from django.db import router, DEFAULT_DB_ALIAS
    23from django.utils.translation import ugettext_lazy as _
    34from django.utils.encoding import smart_text, force_text
    45from django.utils.encoding import python_2_unicode_compatible
     
    165166        method. The ObjectNotExist exception, if thrown, will not be caught,
    166167        so code that calls this method should catch it.
    167168        """
    168         return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
     169        return self.model_class()._base_manager.using(
     170            router.db_for_read(self.model_class()) or DEFAULT_DB_ALIAS
     171        ).get(**kwargs)
    169172
    170173    def get_all_objects_for_this_type(self, **kwargs):
    171174        """
    172175        Returns all objects of this type for the keyword arguments given.
    173176        """
    174         return self.model_class()._base_manager.using(self._state.db).filter(**kwargs)
     177        return self.model_class()._base_manager.using(
     178            router.db_for_read(self.model_class()) or DEFAULT_DB_ALIAS
     179        ).filter(**kwargs)
    175180
    176181    def natural_key(self):
    177182        return (self.app_label, self.model)
Back to Top