Made sure the models and admin looked right and worked with Stories

This commit is contained in:
Corey Oordt 2009-07-08 09:01:27 -04:00
parent ece93fd92d
commit fc2ae672e6
2 changed files with 21 additions and 2 deletions

View file

@ -5,8 +5,27 @@ from django.template.defaultfilters import slugify
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

View file

@ -23,7 +23,7 @@ class Category(models.Model):
class Meta:
verbose_name_plural = 'categories'
unique_together = (('parent', 'name'),)
unique_together = ('parent', 'name')
ordering = ('name',)
def __unicode__(self):