• Members 50 posts
    June 24, 2018, 5:30 p.m.

    I have a custom index page which has nothing to do with the forum. The only relation to it, is that I want to show the two or three latest threads from misago in the sidebar.
    I want to show:

    • Thread title
    • Text/body (I'll cut it off using css)
    • Date/time created
    • Thumbnail of user avatar (like in misago's index).

    Would it be possible to get the data and share it with my index/frontpage app?

    I'm thinking something in the line of getting context data like this in the index/frontpage apps view.

    from relevant.misago.models import title, text, avatar, date/time

    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        context['latest_title2'] = relevant.objects.values_list('relevantobject', flat=True).latest
        context['latest_title1'] = relevant.objects.values_list('relevantobject', flat=True).order_by('-pk')[1]
        context['latest_text2'] = relevant.objects.values_list('relevantobject', flat=True).latest
        context['latest_text1'] = relevant.objects.values_list('relevantobject', flat=True).order_by('-pk')[1]
        context['latest_date/time2'] = relevant.objects.values_list('relevantobject', flat=True).latest
        context['latest_date/time1'] = relevant.objects.values_list('relevantobject', flat=True).order_by('-pk')[1]
        context['latest_avatar2'] = relevant.objects.values_list('relevantobject', flat=True).latest
        context['latest_avatar1'] = relevant.objects.values_list('relevantobject', flat=True).order_by('-pk')[1]
  • Aug. 13, 2018, 5:45 p.m.

    Marked as best answer by Aug. 13, 2018, 6:03 p.m..

    Woah, I've really dropped the ball on this one, sorry!

    from misago.categories.models import Category
    from misago.threads.viewmodels import ForumThreads
    root_category = Category.objects.root_category()
    viewmodel = ViewModel(request, root_category, 'all', 1)
    threads = viewmodel.get_template_context()['threads']

    Thats the code that Misago uses to display first page of threads list. It respects permissions and provides all that you are after.

    You could then slice the threads to last three via threads[:3].

  • arrow_forward