Hello Ivan... you say Unrelated but I see you have a relation with
VendorGroup... why don't use a ForeignKey?... any way you can use the pipe
charater " | " to concatenate two querysets.

https://simpleisbetterthancomplex.com/tips/2016/06/20/django-tip-5-how-to-merge-querysets.html


Cheers!

Rafael E. Ferrero


El lun., 20 may. 2019 a las 9:12, Ivan Martić (<[email protected]>)
escribió:

> 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,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f0413341-91b2-4308-afd5-ae486b09a71e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f0413341-91b2-4308-afd5-ae486b09a71e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJJc_8XZ00Sw%2B-o%3D%2B7xY7cHP6wL_TqMMeHmR7RSC5k71hvvRfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to