| Issue 70: | Suggestion to add TreeNodeMultipleChoiceField | |
| 1 person starred this issue and may be notified of changes. | Back to list |
I suggest to add this useful field in mptt/forms.py when we have ManyToManyField in model:
class TreeNodeMultipleChoiceField(forms.ModelMultipleChoiceField):
"""A ModelMultipleChoiceField for tree nodes."""
def __init__(self, level_indicator=u'---', *args, **kwargs):
self.level_indicator = level_indicator
super(TreeNodeMultipleChoiceField, 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),
smart_unicode(obj))
Sep 9, 2010
Added in http://github.com/django-mptt/django-mptt/commit/7edad737c9e72a9be4ad04f8f013429fff7dd343 (some tweaks to the above patch, but usage is the same)
Status:
Fixed
|
Labels: Milestone-Release0.4