From 0fa7402f1d4a89476390ddc2934c57a467fff00e Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Wed, 11 May 2011 07:08:06 -0400 Subject: [PATCH] Added some specialized functions for relations --- categories/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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')