Created
June 16, 2009 02:22
-
-
Save benspaulding/130488 to your computer and use it in GitHub Desktop.
Asking for some QuerySet help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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