【发布时间】:2019-07-16 05:45:52
【问题描述】:
如何使这个范围正常工作。每当我限制n 时,它都会无限制地给出每个结果。这里我使用了Destination(),它是models.py中的一个类
# This is to show you
def generator(f, n, *args, **kwargs):
return (f(*args, **kwargs) for __ in range(n))
# Here is a problem
target1 = Destination.objects.all()
for field in target1:
[Destination(img = f'{field.img}',title = f'{field.title}') for __ in range(2)]
#models.py
class Destination(models.Model):
title = models.CharField(max_length=255)
img = models.CharField(max_length=255)
【问题讨论】: