+ node = models.ForeignKey(Node, related_name='navigation_set', help_text="Be available as navigation for this node.")
+ key = models.CharField(max_length=255, validators=[RegexValidator("\w+")], help_text="Must contain one or more alphanumeric characters or underscores.")
+ depth = models.PositiveSmallIntegerField(default=DEFAULT_NAVIGATION_DEPTH, validators=[MinValueValidator(1)], help_text="Defines the maximum display depth of this navigation.")
+
+ def __init__(self, *args, **kwargs):
+ super(Navigation, self).__init__(*args, **kwargs)
+ self._initial_data = model_to_dict(self)
+
+ def __unicode__(self):
+ return "%s[%s]" % (self.node, self.key)
+
+ def _has_changed(self):
+ return self._initial_data != model_to_dict(self)
+
+ def save(self, *args, **kwargs):
+ super(Navigation, self).save(*args, **kwargs)
+
+ if self._has_changed():
+ Navigation.objects.clear_cache_for(self.node)
+ self._initial_data = model_to_dict(self)
+
+ def delete(self, *args, **kwargs):
+ super(Navigation, self).delete(*args, **kwargs)
+ Navigation.objects.clear_cache_for(self.node)
+
+ class Meta:
+ unique_together = ('node', 'key')
+
+
+class NavigationItemManager(TreeManager):
+ use_for_related = True
+
+ def get_queryset(self):
+ return NavigationCacheQuerySet(self.model, using=self._db)
+
+
+class NavigationItem(TreeEntity):
+ objects = NavigationItemManager()