Monday, February 24, 2014

Re: How to return Random items from a Mongodb Resource

On Monday, February 24, 2014 8:28:23 AM UTC-4:30, Anuj Chauhan wrote:
Hi Friends,

I need to return random items from a tastypie resource which is a resources.MongoEngineResource.

I have already tried using MyClass.objects.all().order_by('?'), but it simply keep returning the same rows always. Following is the code of my resource.
Hello,

You should use the Python's built-in random module. See random.sample()

Regards,
Camilo

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/485cabc9-86f1-4a2e-8e09-0fc744e76c43%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment