Skip to content

Commit

Permalink
Added some specialized functions for relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Oordt committed May 11, 2011
1 parent 8d46659 commit 0fa7402
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ def get_absolute_url(self):
ancestors = list(self.get_ancestors()) + [self,]
return prefix + '/'.join([force_unicode(i.slug) for i in ancestors]) + '/'

if RELATION_MODELS:
def get_related_content_type(self, content_type):
"""
Get all related items of the specified content type
"""
return self.storyrelation_set.filter(
content_type__name=content_type)

def get_relation_type(self, relation_type):
"""
Get all relations of the specified relation type
"""
return self.storyrelation_set.filter(relation_type=relation_type)

class Meta:
verbose_name_plural = 'categories'
unique_together = ('parent', 'name')
Expand Down

0 comments on commit 0fa7402

Please sign in to comment.