Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
130192b1
Kaydet (Commit)
130192b1
authored
Ock 21, 2019
tarafından
Pavel Savchenko
Kaydeden (comit)
Tim Graham
Ock 21, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Corrected GenericRelation's related_query_name manual lookup example.
And changed related_query_name to a singular noun.
üst
d15c61ca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
contenttypes.txt
docs/ref/contrib/contenttypes.txt
+6
-6
No files found.
docs/ref/contrib/contenttypes.txt
Dosyayı görüntüle @
130192b1
...
@@ -394,21 +394,21 @@ be used to retrieve their associated ``TaggedItems``::
...
@@ -394,21 +394,21 @@ be used to retrieve their associated ``TaggedItems``::
Defining :class:`~django.contrib.contenttypes.fields.GenericRelation` with
Defining :class:`~django.contrib.contenttypes.fields.GenericRelation` with
``related_query_name`` set allows querying from the related object::
``related_query_name`` set allows querying from the related object::
tags = GenericRelation(TaggedItem, related_query_name='bookmark
s
')
tags = GenericRelation(TaggedItem, related_query_name='bookmark')
This enables filtering, ordering, and other query operations on ``Bookmark``
This enables filtering, ordering, and other query operations on ``Bookmark``
from ``TaggedItem``::
from ``TaggedItem``::
>>> # Get all tags belonging to bookmarks containing `django` in the url
>>> # Get all tags belonging to bookmarks containing `django` in the url
>>> TaggedItem.objects.filter(bookmark
s
__url__contains='django')
>>> TaggedItem.objects.filter(bookmark__url__contains='django')
<QuerySet [<TaggedItem: django>, <TaggedItem: python>]>
<QuerySet [<TaggedItem: django>, <TaggedItem: python>]>
Of course, if you don't add the
reverse relationship
, you can do the
Of course, if you don't add the
``related_query_name``
, you can do the
same types of lookups manually::
same types of lookups manually::
>>> b
= Bookmark.objects.get(url='https://www.djangoproject.com/
')
>>> b
ookmarks = Bookmark.objects.filter(url__contains='django
')
>>> bookmark_type = ContentType.objects.get_for_model(
b
)
>>> bookmark_type = ContentType.objects.get_for_model(
Bookmark
)
>>> TaggedItem.objects.filter(content_type__pk=bookmark_type.id, object_id
=b.id
)
>>> TaggedItem.objects.filter(content_type__pk=bookmark_type.id, object_id
__in=bookmarks
)
<QuerySet [<TaggedItem: django>, <TaggedItem: python>]>
<QuerySet [<TaggedItem: django>, <TaggedItem: python>]>
Just as :class:`~django.contrib.contenttypes.fields.GenericForeignKey`
Just as :class:`~django.contrib.contenttypes.fields.GenericForeignKey`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment