Changeset 3156
- Timestamp:
- 06/19/06 15:19:01 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/modeltests/generic_relations/models.py
r3134 r3156 65 65 66 66 # Objects with declared GenericRelations can be tagged directly -- the API 67 # mimics the many-to-many API 67 # mimics the many-to-many API. 68 68 >>> lion.tags.create(tag="yellow") 69 69 <TaggedItem: yellow> … … 80 80 [<TaggedItem: fatty>, <TaggedItem: salty>] 81 81 82 # You can easily access the content object like a foreign key 82 # You can easily access the content object like a foreign key. 83 83 >>> t = TaggedItem.objects.get(tag="salty") 84 84 >>> t.content_object … … 86 86 87 87 # Recall that the Mineral class doesn't have an explicit GenericRelation 88 # defined. That's OK since you can create TaggedItems explicitally.88 # defined. That's OK, because you can create TaggedItems explicitly. 89 89 >>> tag1 = TaggedItem(content_object=quartz, tag="shiny") 90 90 >>> tag2 = TaggedItem(content_object=quartz, tag="clearish") … … 92 92 >>> tag2.save() 93 93 94 # However, not having the convience takes a small toll when it comes95 # to do lookups94 # However, excluding GenericRelations means your lookups have to be a bit more 95 # explicit. 96 96 >>> from django.contrib.contenttypes.models import ContentType 97 97 >>> ctype = ContentType.objects.get_for_model(quartz) … … 99 99 [<TaggedItem: clearish>, <TaggedItem: shiny>] 100 100 101 # You can set a generic foreign key in the way you'd expect 101 # You can set a generic foreign key in the way you'd expect. 102 102 >>> tag1.content_object = platypus 103 103 >>> tag1.save()
