我将这个Django 博客应用程序类别系统传递给 django-mptt。
我遇到的问题是关于_get_online_category
方法的。此方法允许我仅获取具有Entry
.
def _get_online_categories(self):
"""
Returns categories with entries "online" inside.
Access this through the property ``online_entry_set``.
"""
from models import Entry
return Category.objects.filter(entries__status=Entry.STATUS_ONLINE).distinct()
我该如何修改它,以便我也将拥有具有条目的类别的类别?
例如 :
我Spain > Malaga
和马拉加Entry
用以前的方法得到了一个,我只会得到,Malaga
但Spain
我不想两者都有。
第二个问题:
如何从父类别中获取所有条目?
例如从西班牙获得马拉加的职位?
def _get_online_entries(self):
"""
Returns entries in this category with status of "online".
Access this through the property ``online_entry_set``.
"""
from models import Entry
return self.entries.filter(status=Entry.STATUS_ONLINE)
online_entries = property(_get_online_entries)
这将返回西班牙的空结果。