How to display records from a table related via ForeignKey?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
There is a table of the company, each record is a separate page
class Company(models.Model): user = models.ForeignKey(User, verbose_name=u"Director", blank=True, null=True, on_delete=models.CASCADE) full_name = models.CharField("Full company name", default='"', max_length = 180) email = models.CharField("Email", default=", max_length = 180) background = models.ImageField("Background", upload_to="annex/img/%Y/%m/%d", default=")

How to display data from the second related table ?
class Work(models.Model): associate = models.ForeignKey(Company,blank=True,null=True,default=None, verbose_name=u 'Company', on_delete=models.CASCADE) name = models.CharField("Name", default=", max_length = 180) unit = models.CharField("Ed. ISM", default=", max_length = 30) price = models.CharField("Price per unit", default=", max_length = 20)

Record Company generated new links
path(", ListView.as_view(queryset=Company.objects.all().order_by("name"),template_name="annex/company.html")), url(r'(?P\\d+)$', DetailView.as_view(model=Company template_name="annex/full-company.html")),

I can not understand how to display on the page with company record the appropriate entry of the table Work
by | 7 views

1 Answer

0 like 0 dislike
object.work_set is a queryset of objects of class work. praeteritis on it
something like this:
{% for work in object.work_set.all %} {# here do whatever you want #} {%endfor%}
110,608 questions
257,186 answers
35,573 users