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',)
Ok。ここでは、ツリーのような形式ですべてのカテゴリを取得します。任意のカテゴリをクリックすると、その名前と親だけが表示されます。このスクリーンショットを見てください:
では、django と feincms を介してこのリストを表示するにはどうすればよいでしょうか? それを行うためにテーブルに新しいキーを作成したくありません。