N
N
NikClik2018-06-19 06:04:53
Django
NikClik, 2018-06-19 06:04:53

Outputting information from multiple models to a template?

there are 2 connected models Company and Company Contact Numbers
class CompanyNews(models.Model):
.....
class ConnectNumbers(models.Model):
ShowFor = models.ForeignKey(Company, on_delete=models.CASCADE)
I need to make a template that will display all companies and their data, i.e. numbers that belong to the company too. What to write in the view and in the template?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-06-19
@NikClik

Nothing special. You give the QuerySet template to the CompanyNews model, in the template iterate over the elements in the loop and for each element, loop through the elements from the connectnumbers_set relation as a child .
PS Get to know PEP8 , it's not customary in Python to use CamelCase for fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question