当 Entry 对象的数量大于 5000 个条目时,django 有没有办法更有效地执行以下操作?
模型.py
class Entry(models.Model):
user = models.TextField(db_column='User', blank=True)
date = models.DateTimeField(blank=True)
class Color(models.Model):
color = models.TextField(blank=True)
entry = models.ForeignKey(Entry)
假设我想获得每个条目的所有颜色......
entrys = Entry.objects.all()
for e in entrys:
print e.color_set.all()
我希望能够将每个对象与特定条目相关联。例如,在这样的 csv 表中。
user, color
john, blue
john, orange
bob, green
bob, red
bob, purple
浏览我的所有条目需要几秒钟。有没有更好的办法?