Hi,
Something like this:
post_id = Post.objects.values_list ('id', flat=True).order_by('?').first()
return redirect('postview', id=post_id)
7.1.2018 15.33 "Ronnie Raney" <[email protected]> kirjoitti:
> If I understand you, you suggest using my existing DetailView url which
> shows the detailed Post, but create a view which selects a random pk.
>
> I thought of this but I don’t know how to go about creeating a view that
> selects a random pk, then applies to the existing urlpattern.
>
> My guess is to count() the Post objects, then randomly pick one of the
> objects. Then somehow grab the primary key, post_id, and somehow insert
> into a urlpattern. Also point to the correct template. Any help appreciated!
>
> --
> 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/493e4623-df7a-4605-8dcc-e88e2db17064%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAHn91oeyEgtyzoXcU%3DXhAWFb2ddbHL2i7aiRvqwfUMvQH%2BkBUg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.