Using random generator in django

class PostListView(ListView):
    model = Post
    template_name = 'feed/home.html'
    context_object_name = 'posts'
    ordering = ['-date_posted']
    paginate_by = 10
    def get_context_data(self, **kwargs):
        context = super(PostListView, self).get_context_data(**kwargs)
        if self.request.user.is_authenticated:
            liked = [i for i in Post.objects.all() if Like.objects.filter(
                user=self.request.user, post=i)]
            context['liked_post'] = liked
        return context


            {% for post in posts %}
                <a href="{{ post.user_name.profile.get_absolute_url }}">
                  <img src="{{ post.user_name.profile.image.url }}" class="rounded-circle" width="30" height="30" alt=""></a>
                 <a href="{{ post.user_name.profile.get_absolute_url }}"><b>{{ post.user_name }}</b></a>
                 <br><small >Posted on {{ post.date_posted }}</small>
                 <p >{{ post.description }}</p>
            {% end for %}

i want to add carousel in the above template for that i want random object (with 4 objects ) so how can i use random objects and where?

Help me in using random object generator in django ?

Back to Top