Good day. I can not solve the issue. There are models:

class TbCompany(models.Model): name = models.CharField( max_length=256) class TbVacancy(models.Model): company = models.ForeignKey( 'TbCompany', on_delete=models.SET_NULL, related_name='companies') position_of_work = models.CharField( max_length=256) class TbVacancyWorker(models.Model): vacancy = models.ForeignKey( 'TbVacancy', on_delete=models.SET_NULL, related_name='vacancies') name = models.CharField( max_length=256) 

urls.py

 url(r'^vacancy/list/$', vacancy_list, name = 'vacancy_list'), url(r'^vacancy/(?P<pk>\d+)/$', vacancy_detail, name = 'vacancy_detail') 

vacancy_list.html

 {% for company in companies %} <P>{{company.name}}</p> {% if company.companies.all.count > 0%} <table class="table table-hover"> <thead> <tr> <th><a href="#">№</a></th> <th><a href="#">Stanowisko</a></th> </tr> </thead> <tbody> {% for i in company.companies.all%} <tr> <td>{{ forloop.counter }}</td> <td><a href="{% КАКОЙ URL СЮДА ПЕРЕДАТЬ %}">{{i.position_of_work}}</a></td> </tr> {% endfor %} </tbody> </table> </div> {% endif %}{% endfor %} 

wiews.py

 def vacancy_list(request): companies = TbCompany.objects.all() return render(request, 'vacancy/vacancy_test.html', {'companies':companies}) 

It is necessary to display a table with a list of tables with job titles. At the same time there should be links to job details. thank

  • And what should company.companies.all.count display? And generally company.companies in a template? After all, you are already submitting the queryset of TbCompany to companies initially. I think this is the wrong architecture. A ForeignKey to TbCompany in TbVacancy means many-to-one: i.e. many vacancies to one company - Alexander
  • I display a list of companies with vacancies in the format: Company1: list of vacancies; Company 2: job list. It's not a problem. The problem is to pass in the url template for job details. That is, a click on a vacancy should display the job details. Direct, or tell me where to dig. Thank you - rioxio
  • Damn, it's simple. It was necessary to just sleep :) The problem is solved. Thanks for the help. PS If someone needs to, in url you need to pass {% url 'vacancy_detail' i.pk%} - rioxio

0