Skip to content

Instantly share code, notes, and snippets.

@benspaulding
Created June 16, 2009 02:22
Show Gist options
  • Save benspaulding/130488 to your computer and use it in GitHub Desktop.
Save benspaulding/130488 to your computer and use it in GitHub Desktop.
Asking for some QuerySet help
from django.db import models
class ThingManager(models.Manager):
"""A manager for public Thing objects."""
def get_query_set(self):
return super(ThingManager, self).get_query_set() # How can I
# get a QuerySet that returns all Thing objects that have at least
# one related Piece object whose is_public attr is True?
class Thing(models.Model):
"""A thing."""
title = models.CharField(max_length=255)
objects = models.Manager()
public = ThingManager()
class Piece(models.Model):
"""A piece of a Thing."""
thing = models.ForeignKey(Thing, related_name='pieces')
is_public = models.BooleanField()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment