For a model
class User(db.Model, BaseUser):
name = CharField()
phone = CharField()
age = IntegerField()
points = IntegerField()
and a list of fields, lst = ['phone', 'name', 'points']
Is there a way to get your query to return the fields in lst
?
I can't find an example in the docs, but it seems like Django's ORM has something like ...get().values(lst)
.
I tried passing the list as an argument to User.select()
, but get
TypeError: issubclass() arg 1 must be a class
I guess I could do something like [getattr(obj, field) for field in lst]
with a resulting object, but seems there should be a better way?
Update: The link to values
in Django's docs is here.
User.select(*[getattr(User, f) for f in lst])
) but was wondering if there's a way to directly pass a list of strings of field names like Django'svalues
method. I'll update the question with a link to the docs I'm referring to. – Lindo