Re: How Choose Random User from database ?

2021-04-21 Thread FIRDOUS BHAT
Scot Hacker's answer is preferable

On Wed, Apr 21, 2021 at 11:31 AM Scot Hacker  wrote:

>
> If the number of records you need to choose randomly between is not huge,
> this works fine:
>
> `User.objects.order_by('?').first()`
>
> You only need turn to use a special function or method if your query takes
> more than a microsecond to return, or you have a ton of traffic. i.e. use
> the ORM for random choices with caution.
>
> ./s
>
>
>
>
> On Monday, April 19, 2021 at 6:19:39 PM UTC-7 mustafab...@gmail.com wrote:
>
>> Thanks !
>>
>>
>>
>> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
>> Windows 10
>>
>>
>>
>> *From: *Kelvin Sajere
>> *Sent: *Tuesday, April 20, 2021 3:58 AM
>> *To: *django...@googlegroups.com
>> *Subject: *Re: How Choose Random User from database ?
>>
>>
>>
>> If you just want a random user, you could just use random.choice(). You
>> can use it in shell, in a function or wherever you want.
>>
>>
>>
>> Example:
>>
>>
>>
>> import random
>>
>> users = User.objects.all() #a list of all users
>>
>> random_user = random.choice(users) #a random user
>>
>>
>>
>> On Mon, Apr 19, 2021 at 20:45 Mustafa Burhani 
>> wrote:
>>
>> I want to Choose random user from databse is possible with django shell
>> or need to create model ? for random function ?
>>
>>
>>
>>
>>
>> Thanks !
>>
>> --
>> 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...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>> --
>>
>> KeLLs
>>
>> --
>> 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...@googlegroups.com.
>>
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CADYqDX1275VyPJcTfnX7%2B%3DtbmMSaFTYxph0m0t%2B-PH3bTLK9Ow%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CADYqDX1275VyPJcTfnX7%2B%3DtbmMSaFTYxph0m0t%2B-PH3bTLK9Ow%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
>>
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fe5658e1-3b1c-447a-90a1-4f0a0c888d41n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/fe5658e1-3b1c-447a-90a1-4f0a0c888d41n%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFB6YJrFyAKth2jonyMCYCLKp1svg2yZoxPYq6GfbW1ap2v%3DsA%40mail.gmail.com.


Re: How Choose Random User from database ?

2021-04-21 Thread Scot Hacker

If the number of records you need to choose randomly between is not huge, 
this works fine:

`User.objects.order_by('?').first()`

You only need turn to use a special function or method if your query takes 
more than a microsecond to return, or you have a ton of traffic. i.e. use 
the ORM for random choices with caution.

./s




On Monday, April 19, 2021 at 6:19:39 PM UTC-7 mustafab...@gmail.com wrote:

> Thanks !
>
>  
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for 
> Windows 10
>
>  
>
> *From: *Kelvin Sajere
> *Sent: *Tuesday, April 20, 2021 3:58 AM
> *To: *django...@googlegroups.com
> *Subject: *Re: How Choose Random User from database ?
>
>  
>
> If you just want a random user, you could just use random.choice(). You 
> can use it in shell, in a function or wherever you want.
>
>  
>
> Example:
>
>  
>
> import random
>
> users = User.objects.all() #a list of all users
>
> random_user = random.choice(users) #a random user
>
>  
>
> On Mon, Apr 19, 2021 at 20:45 Mustafa Burhani  
> wrote:
>
> I want to Choose random user from databse is possible with django shell or 
> need to create model ? for random function ?
>
>  
>
>  
>
> Thanks !
>
> -- 
> 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...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> -- 
>
> KeLLs
>
> -- 
> 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...@googlegroups.com.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CADYqDX1275VyPJcTfnX7%2B%3DtbmMSaFTYxph0m0t%2B-PH3bTLK9Ow%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CADYqDX1275VyPJcTfnX7%2B%3DtbmMSaFTYxph0m0t%2B-PH3bTLK9Ow%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
>  
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fe5658e1-3b1c-447a-90a1-4f0a0c888d41n%40googlegroups.com.


RE: How Choose Random User from database ?

2021-04-19 Thread mustafa burhani
Thanks ! Sent from Mail for Windows 10 From: Kelvin SajereSent: Tuesday, April 20, 2021 3:58 AMTo: django-users@googlegroups.comSubject: Re: How Choose Random User from database ? If you just want a random user, you could just use random.choice(). You can use it in shell, in a function or wherever you want. Example: import randomusers = User.objects.all() #a list of all usersrandom_user = random.choice(users) #a random user On Mon, Apr 19, 2021 at 20:45 Mustafa Burhani <mustafaburhan...@gmail.com> wrote:I want to Choose random user from databse is possible with django shell or need to create model ? for random function ?  Thanks !-- 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+unsubscr...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com.-- KeLLs-- 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+unsubscr...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADYqDX1275VyPJcTfnX7%2B%3DtbmMSaFTYxph0m0t%2B-PH3bTLK9Ow%40mail.gmail.com. 



-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/980871E3-E49B-4C96-8A6E-AECA0B93179D%40hxcore.ol.


Re: How Choose Random User from database ?

2021-04-19 Thread Kelvin Sajere
If you just want a random user, you could just use random.choice(). You can
use it in shell, in a function or wherever you want.

Example:

import random
users = User.objects.all() #a list of all users
random_user = random.choice(users) #a random user

On Mon, Apr 19, 2021 at 20:45 Mustafa Burhani 
wrote:

> I want to Choose random user from databse is possible with django shell or
> need to create model ? for random function ?
>
>
> Thanks !
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com
> 
> .
>
-- 
KeLLs

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYqDX1275VyPJcTfnX7%2B%3DtbmMSaFTYxph0m0t%2B-PH3bTLK9Ow%40mail.gmail.com.


Re: How Choose Random User from database ?

2021-04-19 Thread Joel Tanko
if you already have a table with some rows in it, writing a random function
would work just fine.

# as an example
from random import randint
def select_random_user():
all_users = User.objects.all()
selected = list(all_users)[randint(0, all_users.count())]
return selected

On Tue, 20 Apr 2021 at 01:45, Mustafa Burhani 
wrote:

> I want to Choose random user from databse is possible with django shell or
> need to create model ? for random function ?
>
>
> Thanks !
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJ4Kmg6nF1%2B027oUJ-L6jWbM_XGy_3vj9n%2BvkZM42P3BBbLREA%40mail.gmail.com.


How Choose Random User from database ?

2021-04-19 Thread Mustafa Burhani
I want to Choose random user from databse is possible with django shell or 
need to create model ? for random function ?


Thanks !

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/055d5a55-ad28-4a97-b1ec-1d16369cc2a2n%40googlegroups.com.