On Wed, 2006-05-17 at 12:56 -0700, [EMAIL PROTECTED] wrote: > Hi list, > > I'm new to Django, but I've been writing web applications for years in > Perl and PHP. A popular feature these days, are of course tagging > things. > > Tagging things is easy. You have a relational table, containing your > entry ID and a tag associated with it. This could easily be done with a > ManyToManyField() in Django. There is one problem, though. > > I have a search functionality on my page, which ideally allows people > to write a list of tags, and retrieve the entries that has those > associated. Maybe I'm overlooking the obvious here--I hope I am--but > this has become increasingly difficult to implement. It's not as simple > as writing WHERE tag = 'foo' OR tag = 'bar'. That assumes that both > values are met in a single row/join.
I think I'm understanding what you are saying here, but maybe not. So let me make my assumptions clear up front... Your problem with the above WHERE clause is just that the tags might be in a different table, right? As they would be if implemented with Django's ManyToManyField? Django handles the attribute access between models like this reasonably transparently. To wit: class Tag(models.Model): name = models.CharField(maxlength = 50) class Entry(models.Model): title = models.CharField(maxlength = 50) tags = models.ManyToManyField(Tag) # Get all entries corresponding to tags in the list tag_list entries = Entry.objects.filter(tags__name__in = tag_list) As per normal SQL, if one or more of the entries in tag_list have no corresponding entry, then that is no problem. I suspect I am missing something here, since what I have shown here is more or less the same as the database API documentatiokn explains (http://www.djangoproject.com/documentation/db_api/#many-to-many-relationships ). So why doesn't this do what you want? Regards, 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 -~----------~----~----~----~------~----~------~--~---