Skip to content

Commit

Permalink
Made sure the models and admin looked right and worked with Stories
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Oordt committed Jul 8, 2009
1 parent ece93fd commit fc2ae67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion categories/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@
from mptt.forms import TreeNodeChoiceField
from editor import TreeEditorMixin

class NullTreeNodeChoiceField(forms.ModelChoiceField):
"""A ModelChoiceField for tree nodes."""
def __init__(self, level_indicator=u'---', *args, **kwargs):
self.level_indicator = level_indicator
#kwargs['empty_label'] = None
super(NullTreeNodeChoiceField, self).__init__(*args, **kwargs)

def label_from_instance(self, obj):
"""
Creates labels which represent the tree level of each node when
generating option labels.
"""
return u'%s %s' % (self.level_indicator * getattr(obj, obj._meta.level_attr),
obj)


class CategoryAdminForm(forms.ModelForm):
parent = TreeNodeChoiceField(queryset=Category.tree.all(), level_indicator=u'+-', required=False)
parent = NullTreeNodeChoiceField(queryset=Category.tree.all(),
level_indicator=u'+-',
empty_label='------',
required=False)
class Meta:
model = Category

Expand Down
2 changes: 1 addition & 1 deletion categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_absolute_url(self):

class Meta:
verbose_name_plural = 'categories'
unique_together = (('parent', 'name'),)
unique_together = ('parent', 'name')
ordering = ('name',)

def __unicode__(self):
Expand Down

0 comments on commit fc2ae67

Please sign in to comment.