Re: How to get a list of queryset selected fields

2017-06-15 Thread Todor Velichkov
ts.values().first() > which will return None if the queryset is empty, which doesn't have an > attribute of .keys(). > > > -Original Message- > From: django...@googlegroups.com [mailto: > django...@googlegroups.com ] On Behalf Of Todor Velichkov > Sent:

RE: How to get a list of queryset selected fields

2017-06-15 Thread Matthew Pava
ribute of .keys(). -Original Message- From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Todor Velichkov Sent: Thursday, June 15, 2017 12:36 PM To: Django users Subject: RE: How to get a list of queryset selected fields Hello, Matthew Pava, thank you for your a

Re: How to get a list of queryset selected fields

2017-06-15 Thread Todor Velichkov
Hi, Bruno Soares, well values_list is not what I'm looking for, I'm searching for a list of field names, not field values. Imagine you have a queryset you know nothing about it (how it gets generated) and you want to build a representation (table) of it. The first thing would be to render the

RE: How to get a list of queryset selected fields

2017-06-15 Thread Todor Velichkov
Hello, Matthew Pava, thank you for your answer. This is probably the solution which I'm going to use if there isn't anything better, but overall I don't like this approach for a few reasons: 1) Dict keys are unordered, I would prefer to be ordered as requested (or as defined in the Model) I gu

Re: How to get a list of queryset selected fields

2017-06-15 Thread Bruno Soares
> > Take a look at `values_list` too. https://docs.djangoproject.com/en/dev/ref/models/querysets/#values-list Em quinta-feira, 15 de junho de 2017 12:51:56 UTC-3, Todor Velichkov escreveu: > > That's it, I want to get

RE: How to get a list of queryset selected fields

2017-06-15 Thread Matthew Pava
Behalf Of Todor Velichkov Sent: Thursday, June 15, 2017 10:52 AM To: Django users Subject: How to get a list of queryset selected fields That's it, I want to get a list of all fields which are going to be selected by a queryset, is it possible? e.g. qs = MyModel.objects.only('id',

How to get a list of queryset selected fields

2017-06-15 Thread Todor Velichkov
That's it, I want to get a list of all fields which are going to be selected by a queryset, is it possible? e.g. qs = MyModel.objects.only('id', 'name') select = qs.query.select #should be ['id','name'] PS. I notice there is a `qs.query.select`, but its empty. No idea if its the same as what