[英]How to use a list inside values_list() in django?
I am new to python and django.I am having a list obtained dynamically containing database table fieldnames. 我是python和django的新手。我有一个动态获取的包含数据库表字段名的列表。 How do I use this list within values_list() in django queryset while fetching results from database?
在从数据库中获取结果时,如何在django queryset中的values_list()中使用此列表?
fieldList=['field1','field2'] #list containing table fields
obj=sampletable.objects.filter(somecondition).values_list(fieldlist) #--->want like this
I came to know that we can't use lists simply as it is inside values_list().So I converted it into a string like this and then tried it but in vain. 我开始知道我们不能简单地使用列表,因为它在values_list()里面。所以我把它转换成这样的字符串然后尝试但是徒劳无功。
fieldListstr=','.join(repr(e) for e in fieldList)
This is the error which I got 这是我得到的错误
Cannot resolve keyword "'field1','field2'" into field. Choices are: field1, field2
Please help me with your solutions. 请帮我解决你的问题。 And thanks in advance
并提前感谢
只需打开包装,
.values_list(*fieldlist)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.