mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Made sure the models and admin looked right and worked with Stories
This commit is contained in:
parent
ece93fd92d
commit
fc2ae672e6
2 changed files with 21 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue