Using random generator in django
views.py
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
home.html
<div>
{% for post in posts %}
<div>
<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>
<br><br>
<p >{{ post.description }}</p>
</div>
{% end for %}
</div>
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 ?