+ 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()
+
+ navigation = models.ForeignKey(Navigation, blank=True, null=True, related_name='roots', help_text="Be a root in this navigation tree.")
+ text = models.CharField(max_length=50)
+
+ target_node = models.ForeignKey(Node, blank=True, null=True, related_name='navigation_items', help_text="Point to this node's url.")