使用FeinCMS的Django可以显示表中的任何内容,看起来很不错。但是,如果我必须显示某些表中没有的数据呢?
这是我的代码:
## models.py ##
## This is my main class.
class Application(models.Model):
name = models.CharField(max_length=100)
category = TreeForeignKey('Category', blank=False, null=False, verbose_name="name")
....
class Meta:
ordering = ('category__tree_id', 'category__lft', 'name')
## This is my category class.
class Category(MPTTModel):
name = models.CharField(max_length=50, unique = True)
parent = TreeForeignKey('self', blank=True, null=True, related_name='children')
class MPTTMeta:
include_self = False
order_insertion_by = ['name',]
ordering = ['tree_id', 'lft']
## This function returns list that I need to show in admin interface. As you can see I have to show name of every object which belongs to category.
def get_trailer(self):
application = Application()
apps_list = [application.__unicode__() for application in Application.objects.filter(category=self.id)]
logging.error("This is apps_list from get_trailer!")
logging.error(apps_list)
return apps_list
## Registering Category model as MPTT.
mptt.register(Category, order_insertion_by=['name'])
这里我们得到了管理界面的代码:
## admin.py ##
## This is class for show Application.
class ApplicationAdmin(admin.ModelAdmin):
list_display = ('name', 'category')
list_filter = ('category',)
ordering = ('category__lft',)
## This is class for show Category.
class CategoryAdmin(tree_editor.TreeEditor):
list_display = ('name', 'id',)
list_filter = ('parent',)
ordering = ('category__lft',)
确定。在这里,我们以树状格式获取所有类别。当我们点击任何类别时,我们只看到它的名字和父母。看看这个截图:
那么,如何通过django和feincms显示这个列表?我不想在表格中创建新的密钥。