Hi guys, hope you can help me.
I have 2 models and i want to make a count query on them. I need a count on how many articles i have in every category.
Models:
class Vendors(models.Model):
id = models.AutoField(db_column='id', primary_key=True, blank=False, unique=True)
name = models.CharField(db_column='name', max_length=150, blank=True, null=True)
groupid = models.IntegerField(db_column='groupid', blank=True, null=True)
class VendorGroup(models.Model):
id = models.AutoField(db_column='ID', primary_key=True, null=False, max_length=255, blank=True)
vendor_group = models.CharField(db_column='Vendor Group', max_length=255, blank=True, null=True)
view:
def vendorsgrouping_view(request):
list_vendor = VendorGroup.objects.all().order_by('vendor_group')
context = {
'lista_vendora':lista_vendora,
}
return render(request, "templates/vendorgroup.html", context)
I have list of vendors listed in template:
{% for item in lista_vendora %}
{{ item.vendor_group }}
{% endfor %}
Prefetch, annotate, select related dont work since they are not connected. I know it is easier to give foreign key to fields but what about this?
Thanks,