Also, would something like this work, and would it be a way to create the
view?
class RandomDetailView(DetailView):
model = Post
def random_post(request):
post_ids = Post.objects.all().values_list('post_id', flat=True)
random_obj = Post.objects.get(id=random.choice(post_ids)) ### Is
"id" here supposed to be pk, or post_id?
context = {'random_obj':random_obj,}
return render(request, 'blog/random_post.html', context)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/e647327a-6f64-4cb1-a4fc-c5188db010ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.