Get certain value of all objects

Hello everyone,

I have a quick question.
i have a model that looks like this:

class Company(models.Model):
    title = models.CharField(max_length=200)
    address = models.CharField(max_length=200)

I want to make an array of all titles that are currently in database. I tried y = Company.objects.all().values(‘title’) but i get an object instead of values like y = [“Audi”, “BMW”]
Is there any “elegant” way of getting values?

Thank you in advance.

Nevermind, I’m stupid. It’s literally first code in the documentation: QuerySet API reference | Django documentation | Django

I would describe this documentation as neat, and to the point in some parts…not in others.

When it comes to retrieving data from more advanced databases - that of which you might be doing at some point (with many to one relationships and such), it’s sort of all over the place and doesn’t explain things clearly.

This however explains everything well. I just thought I would share it.

1 Like

Thank you for giving me useful resource. Appreciated :smiley: