I am modeling Applications and the ways they are installed on user's devices as follows:
class WindowsUserApplications(models.Model):
application_name = models.CharField(max_length=60, null=False, unique=True)
category = models.ForeignKey('ApplicationCategory', null=False, default=10, on_delete=models.SET_DEFAULT)
class WindowsUserInstalls(models.Model):
device_name = models.CharField(max_length=15, null=False)
version = models.CharField(max_length=30, null=False)
application = models.ForeignKey('WindowsUserApplications', related_name='windows_user_applications', null=False, on_delete=models.CASCADE)
And then, on the view I want to get a list of the installed applications like this:
def user_inventory(request, *args, **kwargs):
user_applications = WindowsUserInstalls.objects.annotate(Count('application'))
template = 'webapp/user_inventory.html'
context = {
'user_applications' : user_applications,
}
return render(request, template, context)
However, I keep getting repeated lines for the installed apps and all of them with an install count of 1, instead of getting them summarized.
I have tried other approaches such as adding .values('application')
to the query, with no luck.
Thanks in advance for any hints.