Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:56:48+00:00 2026-05-31T00:56:48+00:00

I am passing this Django Blog App category system to django-mptt. The problem I

  • 0

I am passing this Django Blog App category system to django-mptt.

The problem I have is about the _get_online_category method.
This method allows me to get only the category having an 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()

How can I modify it so I will have also categories having categories having an entry ?

For example :

I have Spain > Malaga and Malaga got an Entry with the previous method, I will get only Malaga but not Spain I would like to have both.

Second question :

How to get all entries from a parent category ?

For exemple get Malaga’s post from 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)

This returns empty result for Spain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:56:49+00:00Added an answer on May 31, 2026 at 12:56 am

    This looks to be a good solution for the first way :

    def _get_online_categories(self):
        """
        Returns categories with entries "online" inside.
        Access this through the property ``online_entry_set``.
        """
        from models import Entry
        queryset =  self.categories.filter(entries__status=Entry.STATUS_ONLINE)
    
        new_queryset = queryset.none() | queryset
        for obj in queryset:
            new_queryset = new_queryset | obj.get_ancestors()
        return new_queryset
    

    Second question

    Something like this will make it :

    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 Entry.objects.filter(status=Entry.STATUS_ONLINE, 
                                    category__lft__gte=self.lft, 
                                    category__rght__lte=self.rght)
    
    online_entries = property(_get_online_entries)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's about passing values from URL to view in django. URL like this: http:///boards/?
i have data structure i am passing this from server to client using data
I have an ArrayCollection of objects. I'm passing this array to a horizontallist as
I have objects which create other child objects within their constructors, passing 'this' so
Edit: This problem was down to me passing the wrong view to the Touch
Pretty simple. I have a Python list that I am passing to a Django
as per this SO question Django Passing Custom Form Parameters to Formset im tryin
I've used answer from this question: Django: making raw SQL query, passing multiple/repeated params?
I have this models in Django: News Comments Reactions Relations are: a News has
In a Django model passing a param to a method and using it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.