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
ebfa508f
Kaydet (Commit)
ebfa508f
authored
Kas 19, 2013
tarafından
Baptiste Mispelon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added more examples to the get_object_or_404 documentation.
üst
170eedf5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
3 deletions
+30
-3
shortcuts.txt
docs/topics/http/shortcuts.txt
+30
-3
No files found.
docs/topics/http/shortcuts.txt
Dosyayı görüntüle @
ebfa508f
...
@@ -261,9 +261,10 @@ Required arguments
...
@@ -261,9 +261,10 @@ Required arguments
------------------
------------------
``klass``
``klass``
A :class:`~django.db.models.Model`, :class:`~django.db.models.Manager` or
A :class:`~django.db.models.Model` class,
:class:`~django.db.models.query.QuerySet` instance from which to get the
a :class:`~django.db.models.Manager`,
object.
or a :class:`~django.db.models.query.QuerySet` instance from which to get
the object.
``**kwargs``
``**kwargs``
Lookup parameters, which should be in the format accepted by ``get()`` and
Lookup parameters, which should be in the format accepted by ``get()`` and
...
@@ -290,6 +291,32 @@ This example is equivalent to::
...
@@ -290,6 +291,32 @@ This example is equivalent to::
except MyModel.DoesNotExist:
except MyModel.DoesNotExist:
raise Http404
raise Http404
The most common use case is to pass a :class:`~django.db.models.Model`, as
shown above. However, you can also pass a
:class:`~django.db.models.query.QuerySet` instance::
queryset = Book.objects.filter(title__startswith='M')
get_object_or_404(queryset, pk=1)
The above example is a bit contrived since it's equivalent to doing::
get_object_or_404(Book, title__startswith='M', pk=1)
but it can be useful if you are passed the ``queryset`` variable from somewhere
else.
Finally, you can also use a :class:`~django.db.models.Manager`. This is useful
for example if you have a
:ref:`custom manager<custom-managers>`::
get_object_or_404(Book.dahl_objects, title='Matilda')
You can also use
:class:`related managers<django.db.models.fields.related.RelatedManager>`::
author = Author.objects.get(name='Roald Dahl')
get_object_or_404(author.book_set, title='Matilda')
Note: As with ``get()``, a
Note: As with ``get()``, a
:class:`~django.core.exceptions.MultipleObjectsReturned` exception
:class:`~django.core.exceptions.MultipleObjectsReturned` exception
will be raised if more than one object is found.
will be raised if more than one object is found.
...
...
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