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
f8a6a4eb
Kaydet (Commit)
f8a6a4eb
authored
Agu 09, 2013
tarafından
Loic Bistuer
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improved queryset handling and docs for (Single|Multiple)ObjectMixin.
üst
84422688
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
14 deletions
+42
-14
detail.py
django/views/generic/detail.py
+12
-8
list.py
django/views/generic/list.py
+14
-6
mixins-multiple-object.txt
docs/ref/class-based-views/mixins-multiple-object.txt
+8
-0
mixins-single-object.txt
docs/ref/class-based-views/mixins-single-object.txt
+8
-0
No files found.
django/views/generic/detail.py
Dosyayı görüntüle @
f8a6a4eb
...
@@ -57,19 +57,23 @@ class SingleObjectMixin(ContextMixin):
...
@@ -57,19 +57,23 @@ class SingleObjectMixin(ContextMixin):
def
get_queryset
(
self
):
def
get_queryset
(
self
):
"""
"""
Get the queryset to look an object up against. May not be called if
Return the `QuerySet` that will be used to look up the object.
`get_object` is overridden.
Note that this method is called by the default implementation of
`get_object` and may not be called if `get_object` is overriden.
"""
"""
if
self
.
queryset
is
None
:
if
self
.
queryset
is
None
:
if
self
.
model
:
if
self
.
model
:
return
self
.
model
.
_default_manager
.
all
()
return
self
.
model
.
_default_manager
.
all
()
else
:
else
:
raise
ImproperlyConfigured
(
"
%(cls)
s is missing a queryset. Define "
raise
ImproperlyConfigured
(
"
%(cls)
s.model,
%(cls)
s.queryset, or override "
"
%(cls)
s is missing a QuerySet. Define "
"
%(cls)
s.get_queryset()."
%
{
"
%(cls)
s.model,
%(cls)
s.queryset, or override "
'cls'
:
self
.
__class__
.
__name__
"
%(cls)
s.get_queryset()."
%
{
})
'cls'
:
self
.
__class__
.
__name__
return
self
.
queryset
.
_clone
()
}
)
return
self
.
queryset
.
all
()
def
get_slug_field
(
self
):
def
get_slug_field
(
self
):
"""
"""
...
...
django/views/generic/list.py
Dosyayı görüntüle @
f8a6a4eb
...
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
...
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
from
django.core.paginator
import
Paginator
,
InvalidPage
from
django.core.paginator
import
Paginator
,
InvalidPage
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
from
django.db.models.query
import
QuerySet
from
django.http
import
Http404
from
django.http
import
Http404
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.views.generic.base
import
TemplateResponseMixin
,
ContextMixin
,
View
from
django.views.generic.base
import
TemplateResponseMixin
,
ContextMixin
,
View
...
@@ -22,18 +23,25 @@ class MultipleObjectMixin(ContextMixin):
...
@@ -22,18 +23,25 @@ class MultipleObjectMixin(ContextMixin):
def
get_queryset
(
self
):
def
get_queryset
(
self
):
"""
"""
Get the list of items for this view. This must be an iterable, and may
Return the list of items for this view.
be a queryset (in which qs-specific behavior will be enabled).
The return value must be an iterable and may be an instance of
`QuerySet` in which case `QuerySet` specific behavior will be enabled.
"""
"""
if
self
.
queryset
is
not
None
:
if
self
.
queryset
is
not
None
:
queryset
=
self
.
queryset
queryset
=
self
.
queryset
if
hasattr
(
queryset
,
'_clone'
):
if
isinstance
(
queryset
,
QuerySet
):
queryset
=
queryset
.
_clone
()
queryset
=
queryset
.
all
()
elif
self
.
model
is
not
None
:
elif
self
.
model
is
not
None
:
queryset
=
self
.
model
.
_default_manager
.
all
()
queryset
=
self
.
model
.
_default_manager
.
all
()
else
:
else
:
raise
ImproperlyConfigured
(
"'
%
s' must define 'queryset' or 'model'"
raise
ImproperlyConfigured
(
%
self
.
__class__
.
__name__
)
"
%(cls)
s is missing a QuerySet. Define "
"
%(cls)
s.model,
%(cls)
s.queryset, or override "
"
%(cls)
s.get_queryset()."
%
{
'cls'
:
self
.
__class__
.
__name__
}
)
return
queryset
return
queryset
def
paginate_queryset
(
self
,
queryset
,
page_size
):
def
paginate_queryset
(
self
,
queryset
,
page_size
):
...
...
docs/ref/class-based-views/mixins-multiple-object.txt
Dosyayı görüntüle @
f8a6a4eb
...
@@ -63,6 +63,14 @@ MultipleObjectMixin
...
@@ -63,6 +63,14 @@ MultipleObjectMixin
A ``QuerySet`` that represents the objects. If provided, the value of
A ``QuerySet`` that represents the objects. If provided, the value of
``queryset`` supersedes the value provided for :attr:`model`.
``queryset`` supersedes the value provided for :attr:`model`.
.. warning::
``queryset`` is a class attribute with a *mutable* value so care
must be taken when using it directly. Before using it, either call
its :meth:`~django.db.models.query.QuerySet.all` method or
retrieve it with :meth:`get_queryset` which takes care of the
cloning behind the scenes.
.. attribute:: paginate_by
.. attribute:: paginate_by
An integer specifying how many objects should be displayed per page. If
An integer specifying how many objects should be displayed per page. If
...
...
docs/ref/class-based-views/mixins-single-object.txt
Dosyayı görüntüle @
f8a6a4eb
...
@@ -23,6 +23,14 @@ SingleObjectMixin
...
@@ -23,6 +23,14 @@ SingleObjectMixin
A ``QuerySet`` that represents the objects. If provided, the value of
A ``QuerySet`` that represents the objects. If provided, the value of
``queryset`` supersedes the value provided for :attr:`model`.
``queryset`` supersedes the value provided for :attr:`model`.
.. warning::
``queryset`` is a class attribute with a *mutable* value so care
must be taken when using it directly. Before using it, either call
its :meth:`~django.db.models.query.QuerySet.all` method or
retrieve it with :meth:`get_queryset` which takes care of the
cloning behind the scenes.
.. attribute:: slug_field
.. attribute:: slug_field
The name of the field on the model that contains the slug. By default,
The name of the field on the model that contains the slug. By default,
...
...
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