git.ithinksw.org
/
philo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Minor optimization to AttributeForm. Very slightly reduces the number of queries...
[philo.git]
/
philo
/
contrib
/
shipherd
/
models.py
diff --git
a/philo/contrib/shipherd/models.py
b/philo/contrib/shipherd/models.py
index
a520fbe
..
de9a869
100644
(file)
--- a/
philo/contrib/shipherd/models.py
+++ b/
philo/contrib/shipherd/models.py
@@
-7,7
+7,7
@@
from django.core.validators import RegexValidator, MinValueValidator
from django.db import models
from django.forms.models import model_to_dict
from django.db import models
from django.forms.models import model_to_dict
-from philo.models.base import TreeEntity, TreeManager, Entity
+from philo.models.base import TreeEntity, Tree
Entity
Manager, Entity
from philo.models.nodes import Node, TargetURLModel
from philo.models.nodes import Node, TargetURLModel
@@
-163,12
+163,12
@@
class NavigationManager(models.Manager):
# A distinct query is not strictly necessary. TODO: benchmark the efficiency
# with/without distinct.
# A distinct query is not strictly necessary. TODO: benchmark the efficiency
# with/without distinct.
- targets =
list(Node.objects.filter(pk__in=target_pks).distinct()
)
+ targets =
dict([(n.pk, n) for n in Node.objects.filter(pk__in=target_pks).distinct()]
)
for cache in caches:
for item in cache['items']:
if item.target_node_id:
for cache in caches:
for item in cache['items']:
if item.target_node_id:
- item.target_node = targets[
targets.index(item.target_node)
]
+ item.target_node = targets[
item.target_node_id
]
def clear_cache(self):
"""Clears the manager's entire navigation cache."""
def clear_cache(self):
"""Clears the manager's entire navigation cache."""
@@
-224,7
+224,7
@@
class Navigation(Entity):
unique_together = ('node', 'key')
unique_together = ('node', 'key')
-class NavigationItemManager(TreeManager):
+class NavigationItemManager(Tree
Entity
Manager):
use_for_related = True
def get_query_set(self):
use_for_related = True
def get_query_set(self):
@@
-249,8
+249,9
@@
class NavigationItem(TreeEntity, TargetURLModel):
self._initial_data = model_to_dict(self)
self._is_cached = False
self._initial_data = model_to_dict(self)
self._is_cached = False
- def __unicode__(self):
- return self.get_path(field='text', pathsep=u' › ')
+ def get_path(self, root=None, pathsep=u' › ', field='text'):
+ return super(NavigationItem, self).get_path(root, pathsep, field)
+ path = property(get_path)
def clean(self):
super(NavigationItem, self).clean()
def clean(self):
super(NavigationItem, self).clean()