0👍
if query is a queryset, then the variable i is an object.
you can get the object attributes like normally with object.attribute syntax (that is, i.name, i.host, etc.)
make a regular html out of the attributes you pull out of the loop.
You can perform a raw sql query like the following example:
first_person = Person.objects.raw(‘SELECT name, address from myapp_person’)
for some model Person
You should definitely checkout the django documentation.
https://docs.djangoproject.com/en/1.4/
- [Answer]-Django max based on foreign key queryset
- [Answer]-Post file using jquery in Django
- [Answer]-Django inner join on self. Is there a more efficient approach?
- [Answer]-Django connect temporary pre_save signal
- [Answer]-Get gallery thumb from inline photo
0👍
You can use Entry.objects.values('field1','field2','field3')
which will return a list dictionary i.e [{'field1':value1,'field2':value2,'field3':value3},..]
Or alternatively you could use Entry.objects.values_list('field1','field2','field3')
which will return a list of tuples of values i.e [(value1,value2,value3),..]
. In case you are trying to get just one field from the database this can work Entry.objects.values_list('field1',flat=True)
the flat parameter will return a list of values instead of list of tuples of values i.e [value1a,value1b,value1c]
- [Answer]-Django 1.6 models.Manager Complaining about to many values to unpack
- [Answer]-Django built-in User Model implementation