[Answer]-How to retrieve django db info

1👍

Acutally, example is an instance of django.db.models.query.ValuesQuerySet, not just a simple list, it’s a queryset

Because of example is a query set, you can use query set method, do whatever you want.The django queryset document is helpful.

you can traverse example variable like this:

for item in example:
  do_what_you_want(item)

As you declare in you model, your example may like this:

example = [  
             {'Clients':'clients data','Equipos':'equipos data'},
             {'Clients':'clients data','Equipos':'equipos data'}
          ]

I don’t recommend you to convert your example to list type, if you do this, you can not use the powerfull django query set method.Django queryset method is more powerful than a python native list.

0👍

example = models.object.values()

example will be a kind of iterator of dicts where keys are the field names of a model. To make it a list of dicts just do:

example = list(models.object.values())

So example will look something like this:

[
    {'id': 1, 'Clientes': 'some clientes', 'Equipos': 'some equipos'},
    {'id': 2, 'Clientes': 'anoter clientes', 'Equipos': 'another equipos'}
]

Leave a comment