本文整理汇总了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