Code

Ticket #15610: django_1.5.1_15610.patch

File django_1.5.1_15610.patch, 1.6 KB (added by 4glitch@…, 12 months ago)

This works for me on 1.5.1

  • django/contrib/contenttypes/generic.py

    diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py
    index 5690e6b..425c63a 100644
    a b class GenericForeignKey(object): 
    5555        # using this model 
    5656        ContentType = get_model("contenttypes", "contenttype") 
    5757        if obj: 
    58             return ContentType.objects.db_manager(obj._state.db).get_for_model(obj) 
     58            return ContentType.objects.db_manager(ContentType.objects.db).get_for_model(obj) 
    5959        elif id: 
    6060            return ContentType.objects.db_manager(using).get_for_id(id) 
    6161        else: 
  • django/contrib/contenttypes/models.py

    diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
    index b658655..92e8324 100644
    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 
    class ContentType(models.Model): 
    164165        method. The ObjectNotExist exception, if thrown, will not be caught, 
    165166        so code that calls this method should catch it. 
    166167        """ 
    167         return self.model_class()._base_manager.using(self._state.db).get(**kwargs) 
     168        return self.model_class()._base_manager.using(router.db_for_read(self.model_class()) or DEFAULT_DB_ALIAS).get(**kwargs) 
    168169 
    169170    def get_all_objects_for_this_type(self, **kwargs): 
    170171        """