Skip to content

Commit

Permalink
modified Category model to work with django-mptt 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
joshourisman committed Oct 24, 2010
1 parent 66b6345 commit 04da4c0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext as _

import mptt
from mptt.models import MPTTModel

from settings import RELATION_MODELS, RELATIONS

class Category(models.Model):
class Category(MPTTModel):
parent = models.ForeignKey('self',
blank=True,
null=True,
Expand Down Expand Up @@ -45,18 +45,16 @@ def get_absolute_url(self):
ancestors = list(self.get_ancestors()) + [self,]
return prefix + '/'.join([force_unicode(i.slug) for i in ancestors]) + '/'

class Meta:
class MPTTMeta:
verbose_name_plural = 'categories'
unique_together = ('parent', 'name')
ordering = ('tree_id','lft')
ordering = ('tree_id', 'lft')
order_insertion_by = 'name'

def __unicode__(self):
ancestors = self.get_ancestors()
return ' > '.join([force_unicode(i.name) for i in ancestors]+[self.name,])

try: mptt.register(Category, order_insertion_by=['name'])
except: pass

if RELATION_MODELS:
category_relation_limits = reduce(lambda x,y: x|y, RELATIONS)
class CategoryRelationManager(models.Manager):
Expand Down

0 comments on commit 04da4c0

Please sign in to comment.