Skip to content

Commit

Permalink
Moved the bulk of the Topic class to an abstract base.
Browse files Browse the repository at this point in the history
This will allow for easier data additions to Topic-like subclasses.
  • Loading branch information
Malcolm Tredinnick committed Apr 6, 2009
1 parent 0ff5e7b commit 85e0a33
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions acacia/models.py
Expand Up @@ -38,11 +38,14 @@ def get_subtree(self, full_name):
return self.model.get_tree(self.get_by_full_name(full_name))


class Topic(treebeard_mods.MP_Node):
class AbstractTopic(treebeard_mods.MP_Node):
"""
A node in a hierarchical storage tree, representing topics of some kind.
The name of the topic is the name of the parent, followed by the node's
name (with a configurable separator in between).
This is an abstract base class to allow for including attributes other than
just the name via inheritance.
"""
name = models.CharField(max_length=50)
# Denormalise things a bit so that full name lookups are fast.
Expand All @@ -53,6 +56,9 @@ class Topic(treebeard_mods.MP_Node):

objects = TopicManager()

class Meta(treebeard_mods.MP_Node.Meta):
abstract = True

def __unicode__(self):
if not hasattr(self, "full_name") or not self.full_name:
self._set_full_name()
Expand All @@ -76,5 +82,12 @@ def save(self, *args, **kwargs):
query on each save, but saving is much less common than retrieval).
"""
self._set_full_name()
return super(Topic, self).save(*args, **kwargs)
return super(AbstractTopic, self).save(*args, **kwargs)

class Topic(AbstractTopic):
"""
The basic concrete class for a topic node. API details are defined by the
AbstractTopic base class.
"""
pass

0 comments on commit 85e0a33

Please sign in to comment.