Added some specialized functions for relations

This commit is contained in:
Corey Oordt 2011-05-11 07:08:06 -04:00
parent 8d466591d5
commit 0fa7402f1d

View file

@ -49,6 +49,20 @@ class Category(MPTTModel):
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')