I would like to create a queryset from another one which is obtained from a filter search query.
There are my models :
class A(models.Model):
b = models.ForeignKey(B)
c = models.ForeignKey(C)
score = models.FloatField(default=5)
My first query is to filter A
objects related to a particular B
instance " b_instance
":
a_list = A.objects.filter(b=b_instance)
How can I obtain form " a_list
", a " c_list
" regrouping all " c
" fields objects without refer to make a loop ?
c_list = a_list.values_list('c', flat=True)
将给出来自过滤后的A对象的所有c值的列表
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.