Ticket #10367: 10367-genericrelation-r9907.diff

File 10367-genericrelation-r9907.diff, 970 bytes (added by Tai Lee, 15 years ago)

Updated to include an example.

  • docs/ref/contrib/contenttypes.txt

     
    303303    >>> b.tags.all()
    304304    [<TaggedItem: django>, <TaggedItem: python>]
    305305
     306Note that if the model with a :class:`~django.contrib.contenttypes.generic.GenericForeignKey`
     307that you're referring to uses a non-default value for ``ct_field`` or ``fk_field``
     308(e.g. the :mod:`django.contrib.comments` app uses ``ct_field="object_pk"``),
     309you'll need to pass ``content_type_field`` and ``object_id_field`` to
     310:class:`~django.contrib.contenttypes.generic.GenericRelation`.
     311
     312    comments = generic.GenericRelation(Comment, content_type_field="content_type", object_id_field="object_pk")
     313
    306314If you don't add the reverse relationship, you can do the lookup manually::
    307315
    308316    >>> b = Bookmark.objects.get(url='http://www.djangoproject.com/')
Back to Top