我在这里尝试简单的例子http://www.feinheit.ch/media/labs/feincms/admin.html'
models.py:
class Locations(MPTTModel):
title = models.CharField(max_length=100)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
def __unicode__(self):
return self.title
class Meta:
ordering = ['tree_id', 'lft']
admin.py:
class LocationsAdmin(tree_editor.TreeEditor):
pass
admin.site.register(Locations, LocationsAdmin)
但我在管理界面中的模型我只能移动,但不能剪切或创建子节点。如下面的屏幕截图所示:http://www.feinheit.ch/media/labs/feincms/_images/tree_editor.png。 怎么回事?
答案 0 :(得分:0)
对于“添加孩子”需要这样的事情:
class LocationsAdmin(TreeEditor):
def _actions_column(self, instance):
action = ['<div class="drag_handle"></div>',]
action.append(u'<a href="add/?parent=%(id)s"><img src="%(static)sadmin/img/icon_addlink.gif"></a>'
% {'id': instance.id, 'static': django_settings.STATIC_URL})
return action