本文整理匯總了Python中django.db.models.query.ModelIterable方法的典型用法代碼示例。如果您正苦於以下問題:Python query.ModelIterable方法的具體用法?Python query.ModelIterable怎麽用?Python query.ModelIterable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db.models.query
的用法示例。
在下文中一共展示了query.ModelIterable方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _fetch_all
# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import ModelIterable [as 別名]
def _fetch_all(self):
"""
Completely overrides the QuerySet._fetch_all method by adding the
timestamp to all objects
:return: See django.db.models.query.QuerySet._fetch_all for return
values
"""
if self._result_cache is None:
self._result_cache = list(self.iterator())
# TODO: Do we have to test for ValuesListIterable, ValuesIterable,
# and FlatValuesListIterable here?
if self._iterable_class == ModelIterable:
for x in self._result_cache:
self._set_item_querytime(x)
if self._prefetch_related_lookups and not self._prefetch_done:
self._prefetch_related_objects()
示例2: byDay
# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import ModelIterable [as 別名]
def byDay(self, fromDate, toDate):
request = self.request
class ByDayIterable(ModelIterable):
def __iter__(self):
evods = EventsByDayList(fromDate, toDate)
for page in super().__iter__():
pageFromDate = getLocalDate(page.date,
page.time_from, page.tz)
pageToDate = getLocalDate(page.date,
page.time_to, page.tz)
thisEvent = ThisEvent(page.title, page,
page.get_url(request))
evods.add(thisEvent, pageFromDate, pageToDate)
yield from evods
qs = self._clone()
qs._iterable_class = ByDayIterable
return qs.filter(date__range=(fromDate - _2days, toDate + _2days))
示例3: test_seal_non_sealable_model_iterable_subclass
# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import ModelIterable [as 別名]
def test_seal_non_sealable_model_iterable_subclass(self):
message = (
"iterable_class <class 'django.db.models.query.ModelIterable'> is not a subclass of SealedModelIterable"
)
with self.assertRaisesMessage(TypeError, message):
SeaGull.objects.seal(iterable_class=ModelIterable)
示例4: this
# 需要導入模塊: from django.db.models import query [as 別名]
# 或者: from django.db.models.query import ModelIterable [as 別名]
def this(self):
request = self.request
class ThisEventIterable(ModelIterable):
def __iter__(self):
for page in super().__iter__():
yield ThisEvent(page.title, page, page.get_url(request))
qs = self._clone()
qs._iterable_class = ThisEventIterable
return qs