mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #22207 -- Added support for GenericRelation reverse lookups
GenericRelation now supports an optional related_query_name argument. Setting related_query_name adds a relation from the related object back to the content type for filtering, ordering and other query operations. Thanks to Loic Bistuer for spotting a couple of important issues in his review.
This commit is contained in:
parent
c627da0ccc
commit
b77f26313c
9 changed files with 71 additions and 27 deletions
|
@ -145,11 +145,11 @@ class TaggedItem(models.Model):
|
|||
|
||||
class Bookmark(models.Model):
|
||||
url = models.URLField()
|
||||
tags = GenericRelation(TaggedItem, related_name='bookmarks')
|
||||
tags = GenericRelation(TaggedItem, related_query_name='bookmarks')
|
||||
favorite_tags = GenericRelation(TaggedItem,
|
||||
content_type_field='favorite_ct',
|
||||
object_id_field='favorite_fkey',
|
||||
related_name='favorite_bookmarks')
|
||||
related_query_name='favorite_bookmarks')
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue