On Thu, 2006-05-18 at 12:48 +0200, Jesper Nøhr wrote:
[...]
> I was helped by Malcom on IRC, so the only decent thing to do, is to
> post the solution here.

[...]
> You can call it like this:
> 
> tags = ["foo","bar"]
> 
> all = Contract.objects.from_tags(tags)
> 
> What happens is that you count how many tags match on each contract
> ID. Since you only pick out the relevant tags, the count will equal
> len(tags), if there's a match. This allows you to search for records
> where there's only specific relations, when data is divided across
> tables, in this case with a ManyToManyField().
> 
> It works fairly well and fast on my somewhat limited set of set, but I
> think this would scale fine on a larger scale as well.

For the archives: the problem Jesper was trying to solve was to find all
contracts that have both "foo" _and_ "bar" tags (and possibly others,
but at least that set), not just contracts that had either "foo" or
"bar".

Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to