Skip to content

Instantly share code, notes, and snippets.

@hughes
Created November 16, 2012 16:51
Show Gist options
  • Save hughes/4088912 to your computer and use it in GitHub Desktop.
Save hughes/4088912 to your computer and use it in GitHub Desktop.
class FolderManager(models.Manager):
# so that we can do Folder.objects...
def get_query_set(self):
return super(FolderManager, self).get_query_set().filter(is_folder=True)
class Folder(Item):
'''
this class is kind of funny looking because Items cannot have
a ForeignKey field pointing to a subclass of itself.
'''
objects = FolderManager()
def __init__(self, *args, **kwargs):
# override the default behavior of the is_folder field
self._meta.get_field('is_folder').default = True
super(Folder, self).__init__(*args, **kwargs)
class Meta:
# don't create a table
proxy = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment