Hi,
This might work:
Tag.objects.filter(name__startswith='A').exclude(company=None).order_by('name').all()
Collin
On Friday, November 28, 2014 9:08:42 AM UTC-5, termopro wrote:
I have 2 models:
Companies and Tags.
A company may have several tags associated with it, so Tag contains many-to-many relation to Company.
If i'd like to get Tags starting with "A" i'd write:
tags = Tag.objects.filter(name__startswith='A').order_by(' name').all()
But how do i get the list of tags (beginning with letter 'A') which are associated with at least 1 company ?
In sql it would be something like:
SELECT * FROM
tag
WHERE
name LIKE 'A%' AND id IN (SELECT tag_id FROM tag_organization)
?
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b660f738-b3d7-4cc5-babc-3e47ff7d3542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment