0

I am currently building a simple site where users can login and write comments. Its somewhat similar to a forum but difference is that users will see image/an article and they get to comments on things based what they see. In addition they also get to rate what they see in 5 star scale or thumbs up thumbs down.

I have build this site using django now I want to add another application where I can control who gets to see the 5 star scale vs. thumbs up and thumbs down scale after they log in to the site. I want to randomly pic users as they come into the site and make sure half of the user population see one scale vs the other.

Here are my questions:

How should the random selection take place? Does django has inbuilt function or functionality to do such randomization?

Can someone provide simple example? Here is my thought process on building such thing: We create a model where we keep track of the userid, experimentGroup(5 Star or Thumbs up), Time Then in each template we check if which group the user is in and based on that we adjust the users view?

I am new django so it would be great is someone provides a simple example so I can built upon that. After doing google search I found out a very heavy django application but I would rather user something simple that I can understand and control with my limited knowledge.

add-semi-colons
  • 18,094
  • 55
  • 145
  • 232

1 Answers1

0

You can get objects in a random order by using (from django docs):

<YOUR_MODEL>.objects.order_by('?')

The exact queryset depends of how you define your models

Also django provide a template filter to random a list of items (see django docs)

Last, if above is not enough you can use python random module

juliocesar
  • 5,706
  • 8
  • 44
  • 63