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
You may be looking for values. MyModel.objects.all().values() returns a QuerySet list of dictionaries with the field names as the keys. You can specify which specific fields you want to return by passing them as arguments to values(). MyModel.objects.all().values('id', 'name') Then you can use th