Ticket #5826: generic.diff

File generic.diff, 1.2 KB (added by kgoudeaux <kgoudeaux@…>, 16 years ago)

generic.py patch and generic relations doc test

  • django/contrib/contenttypes/generic.py

     
    4949       
    5050    def __get__(self, instance, instance_type=None):
    5151        if instance is None:
    52             raise AttributeError, u"%s must be accessed via instance" % self.name
     52            return self
    5353
    5454        try:
    5555            return getattr(instance, self.cache_attr)
  • tests/modeltests/generic_relations/models.py

     
    132132>>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()]
    133133[(u'clearish', <ContentType: mineral>, 1), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)]
    134134
     135# Recovering the GenericForeignKey Instance and field names
     136>>> isinstance(TaggedItem.content_object, generic.GenericForeignKey)
     137True
     138>>> TaggedItem.content_object.ct_field
     139'content_type'
     140>>> TaggedItem.content_object.fk_field
     141'object_id'
     142
    135143"""}
Back to Top