diff --git a/categories/models.py b/categories/models.py index a1475c4..1d45785 100644 --- a/categories/models.py +++ b/categories/models.py @@ -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')