Given the following models adapted from http://www.djangoproject.com/documentation/models/generic%5Frelations/
class TaggedItem(models.Model):
"""A tag on an item."""
tag = models.SlugField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
class Vegetable(models.Model):
name = models.CharField(max_length=150)
is_yucky = models.BooleanField(default=True)
edible = models.BooleanField(default=True)
class Mineral(models.Model):
name = models.CharField(max_length=150)
hardness = models.PositiveSmallIntegerField()
edible = models.BooleanField(default=True)
How would I filter TaggedItems so that I get only those with content_objects that are edible?
ideally, something like:
TaggedItem.objects.filter(content_object.edible=True)
What if Vegetable
and Mineral
had is_edible
methods?