Ticket #16048: ticket16048-r16259.diff

File ticket16048-r16259.diff, 2.4 KB (added by Andy Durdin, 13 years ago)

Patch against trunk revision 16259

  • tests/modeltests/generic_relations/tests.py

     
    44from django.test import TestCase
    55
    66from models import (TaggedItem, ValuableTaggedItem, Comparison, Animal,
    7     Vegetable, Mineral)
     7    Vegetable, Mineral, Gecko)
    88
    99
    1010class GenericRelationsTests(TestCase):
     
    223223        self.assertEqual(u''.join(form.as_p() for form in formset.forms), u"""<p><label for="id_x-0-tag">Tag:</label> <input id="id_x-0-tag" type="text" name="x-0-tag" maxlength="50" /></p>
    224224<p><label for="id_x-0-DELETE">Delete:</label> <input type="checkbox" name="x-0-DELETE" id="id_x-0-DELETE" /><input type="hidden" name="x-0-id" id="id_x-0-id" /></p>""")
    225225
     226    def test_gfk_manager(self):
     227        # GenericForeignKey should not use the default manager (which may filter objects) #16048
     228        tailless = Gecko.objects.create(has_tail=False)
     229        tag = TaggedItem.objects.create(content_object=tailless, tag="lizard")
     230        self.assertEqual(tag.content_object, tailless)
    226231
    227232class CustomWidget(forms.CharField):
    228233    pass
  • tests/modeltests/generic_relations/models.py

     
    7878
    7979    def __unicode__(self):
    8080        return self.name
     81
     82class GeckoManager(models.Manager):
     83    def get_query_set(self):
     84        return super(GeckoManager, self).get_query_set().filter(has_tail=True)
     85
     86class Gecko(models.Model):
     87    has_tail = models.BooleanField()
     88    objects = GeckoManager()
  • django/contrib/contenttypes/models.py

     
    100100        method. The ObjectNotExist exception, if thrown, will not be caught,
    101101        so code that calls this method should catch it.
    102102        """
    103         return self.model_class()._default_manager.using(self._state.db).get(**kwargs)
     103        return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
    104104
    105105    def natural_key(self):
    106106        return (self.app_label, self.model)
Back to Top