how to send just one part of an object to template in django -


i want send 1 part of object template.

i have 2 models below:

class person(models.model):     name = models.charfield(max_legth=50)     sure_name = models.charfiled(max_length=50)  class office(models.model):     location = models.charfield(max_legth=50) 

and created model below:

class personoffice(models.model):     person = models.foreignkey(person)     office = models.foreignkey(office) 

now, when take data database, personoffice.objects.all(),the data below:

{     {         "pk": 0,         "person": {             "pk":0,             "name":"harry",             "sure_name":"potter"             },         "office":{             "pk":5,             "location":"toronto"         }     },       {         "pk": 1,         "person": {             "pk":6,             "name":"john",             "sure_name":"kelly"             },         "office":{             "pk":6,             "location":"newyork"         }     }    } 

i want send offices template render function. how can it? thanks

updated want use in template {% %} loop. example:

{% office in offices %}     <p>office location: {{ office.location }}</p> {% endfor %} 

i used below code:

offices = personoffice.objects.all().values('office') print(offices) 

and below result in terminal:

<queryset [{'office': 1}, {'office': 2}, {'office': 11}]> 

you can use values

personoffice.objects.values('office') 

this output queryset office each object.

edit:

personoffice.objects.values('office__location') 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -