Q:

How to get an array with the counts of each field with the same parameter in Django in get_context_data?

I use a ListView for a template that displays all the Vehicles in the database. Each Vehicle can have more Wheels and I'm trying to display in the same tempalte how many views each sensor has. 
The models are related to eachother by a field called "vehicle_id". Any idea how I could do this in views.py?
The line that works to an extent is the following
context['number_of_wheels'] = wheels.objects.filter(vehicle_id= F('vehicle_id')).count()

However, this counts all Wheels in the database and displays the same value for all entries. Any idea how I could count, store and display them individually?

A:

There is no need to add these numbers to a context variable. It would probably add more complexity, for example to match that number with the sensors.
You can .annotate(..) your Sensors, so in the queryset, you can write:
from django.views.generic.list import ListView
from app.models import Sensor

class SensorListView(ListView):
    queryset = Sensor.objects.annotate(
        nviews=Count('sensorview')
    )
    template = 'some_template.html'
Each Sensor that originates from this QuerySet will have an extra attribute nviews that contains the number of related SensorViews.
You can then render this in some_template.html, like:
{% for sensor in object_list %}
    {{ sensor }}: {{ sensor.nviews }}
{% endfor %}

