My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 70: Suggestion to add TreeNodeMultipleChoiceField
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Sep 2010


 
Reported by a.vostrjakov, Apr 19, 2010
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 6, 2010
Project Member #1 craig.ds@gmail.com
(No comment was entered for this change.)
Status: Accepted
Labels: Milestone-Release0.4
Sep 9, 2010
Project Member #2 craig.ds@gmail.com
Added in http://github.com/django-mptt/django-mptt/commit/7edad737c9e72a9be4ad04f8f013429fff7dd343 (some tweaks to the above patch, but usage is the same)

Status: Fixed

Powered by Google Project Hosting