Ticket #14325: fix_genericforeignkey_comparison_and_add_regressiontest.diff

File fix_genericforeignkey_comparison_and_add_regressiontest.diff, 2.6 KB (added by Martin Natano, 14 years ago)

fix + regressiontest

  • django/contrib/contenttypes/generic.py

    diff -Naur Django-1.2.3.orig//django/contrib/contenttypes/generic.py Django-1.2.3/django/contrib/contenttypes/generic.py
    old new  
    4949        # Convenience function using get_model avoids a circular import when
    5050        # using this model
    5151        ContentType = get_model("contenttypes", "contenttype")
    52         if obj:
     52        if obj is not None:
    5353             return ContentType.objects.db_manager(obj._state.db).get_for_model(obj)
    54         elif id:
     54        elif id is not None:
    5555             return ContentType.objects.db_manager(using).get_for_id(id)
    5656        else:
    5757            # This should never happen. I love comments like this, don't you?
  • tests/regressiontests/generic_relations_regress/models.py

    diff -Naur Django-1.2.3.orig//tests/regressiontests/generic_relations_regress/models.py Django-1.2.3/tests/regressiontests/generic_relations_regress/models.py
    old new  
    44
    55__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
    66           'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
    7            'Contact', 'Organization', 'Note')
     7           'Contact', 'Organization', 'Note', 'Meeting')
    88
    99class Link(models.Model):
    1010    content_type = models.ForeignKey(ContentType)
     
    7777    name = models.CharField(max_length=255)
    7878    contacts = models.ManyToManyField(Contact, related_name='organizations')
    7979
     80class Meeting(models.Model):
     81    name = models.CharField(max_length=100)
     82
     83    def __len__(self):
     84        return 0
     85
  • tests/regressiontests/generic_relations_regress/tests.py

    diff -Naur Django-1.2.3.orig//tests/regressiontests/generic_relations_regress/tests.py Django-1.2.3/tests/regressiontests/generic_relations_regress/tests.py
    old new  
    7070            Q(notes__note__icontains=r'other note'))
    7171        self.assertTrue(org_contact in qs)
    7272
     73    def test_not_null_comparison(self):
     74        """
     75        Tests if an object which is logical False can be assigned to a
     76        GenericForeignKey
    7377
     78        Tests for bug http://code.djangoproject.com/ticket/14325
     79        """
     80        meeting = Meeting.objects.create(name='empty meeting')
     81        link = Link(content_object=meeting)
    7482
Back to Top