この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
2 番目の質問:
親カテゴリからすべてのエントリを取得する方法は?
たとえば、スペインからマラガの投稿を取得しますか?
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)
スペインでは空の結果が返されます。