優化查詢我有以下的模型結構: class Container(models.Model):
pass
class Generic(models.Model):
name = models.CharacterField(unique=True)
cont = models.ManyToManyField(Container, null=True)
# It
如何打印在「fields_i_want」中指定的列而不是在模板代碼中對列名進行硬編碼? # Let's say I have this in my view:
foo = Foo.objects.filter(some_field='bar').select('field1', 'field2', 'field3')
fields_i_want = ['field1', 'field2']
我有以下型號,藝術和ArtScore: class Art(models.Model):
title = models.CharField()
class ArtScore(models.Model):
art = models.ForeignKey(Art)
date = models.DateField(auto_now_add = True)
am
我在做標籤搜索功能,用戶可以觀察很多標籤,我把它全部放在一個元組中,現在我想查找所有包含列表中至少一個標籤的文本。 符號:text__contains__in=('asd','dsa') 我唯一的想法是做循環如: q = text.objects.all()
for t in tag_tuple:
q.filter(data__contains=t)
例如:標籤 輸入元組,('c