Quantcast
Viewing all articles
Browse latest Browse all 37

How to get objects in a django joined table

I have two apps each has one model:

company app models.py

class Company(models.Model):   name = models.CharField()   address = models.CharField()

client app models.py

class Client(models.Model):    company = models.ForeignKey(Company)    name = models.CharField()

I have a listview of my company:

class CompanyListView(ListView):    model = Company    form_class = CompanyForm    def get_context_data(self, **kwargs):        context = super(CompanyListView, self).get_context_data(**kwargs)        context[client_list] = ???    return context

My problem is how can I pass to context[client_list] client list count related to a specific company?


Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>