Hi there,


Say I have:

class TaggedItem(models.Model):
     """A tag on an item."""
     tag = models.SlugField()
     content_type = models.ForeignKey(ContentType)
     object_id = models.PositiveIntegerField()

     content_object = models.GenericForeignKey()

     class Meta:
         ordering = ["tag"]

     def __str__(self):
         return self.tag

class Book(models.Model):
     writer = models.ForeignKey(User)
     tags = models.GenericRelation(TaggedItem)


How do I get all Tags for books by Dostoevsky ? :-)

TaggedItem.objects.filter(content_type=ContentType.objects.get_for_model(Book), 
content_object__writer="Dostoevsky")

...doesn't work... And

TaggedItem.objects.filter(content_type=ContentType.objects.get_for_model(Book), 
object_id__in=[ book.id for book in 
Book.objects.filter(writer="Dostoevsky")])

is pretty bad.


Should I be looking at extra( ) or is there a smarter way to go about this?


  - bram

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to