I have a database in which there are records with several fields containing some information.
To get all the data in the table corresponding to some filter, I would do this:
records = Record.objects.filter(fieldA='a')
records, I suppose, is a QuerySet object and contains a "list" of records. It is right?
Now let's say that I need a list of values ββin one field.
If I do this:
records = Record.objects.filter(fieldA='a').only('fieldB')
I still get the request, but now it has some pending fields. I want only a list of values ββthat I would like to capture aka fieldB. I also want to be able to capture the different values ββof field B. I believe that I could just iterate over each record, pull out field B, add it to the list if it does not already exist, and here it is, but there should be a better way.
Thanks!
EDIT: I think I'm looking
Record.objects.values_list('fieldB')
python django
Jpc
source share