顯示具有 mptt 標籤的文章。 顯示所有文章
顯示具有 mptt 標籤的文章。 顯示所有文章

2009年7月21日 星期二

使用mptt來建構treeview

  1. 下載mptt
  2. 修正mptt在執行django1.0下所發生的錯誤
  3. 使用範例如下

3.1在model.py


from django.db import models

import mptt

class Category(models.Model):
name = models.CharField(max_length=50)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')

def __unicode__(self):
return self.name

mptt.register(Category)

3.2執行snycdb

3.3輸入資料顯示結果