Re: When to use get_user_model()

2018-02-20 Thread Scot Hacker
It's good future-proofing, in case you ever change the User model in your 
project. In real life, that's highly unlikely, but where it's *really 
important* to use get_user_model() is when you are writing reusable apps 
for distribution. If your app is intended to be dropped into any existing 
Django project, you have no idea what User model is in use by other 
people's projects. This layer of abstraction makes it possible for 
re-usable apps that depend on some User model existing to work no matter 
what.

./s


On Saturday, February 17, 2018 at 2:41:12 PM UTC-8, tangoward15 wrote:
>
>
> Hi, 
>
> I am playing around with user registration. I came across a code where the 
> get_user_model() was assigned to a model in Meta class inside a form. I was 
> just wondering, what is the benefit of using the get_user_model() as Model 
> in a form instead of importing a class from models.py then use that class 
> as model of the form and when should I use it?
>
> models.py
> class RegUser(User):
>
> def __str__(self):
> return self.username
>
> forms.py
>
> class UserCreateForm(UserCreationForm):
>
> class Meta:
> fields = ('username', 'password1', 'password2')
> model = get_user_model()
>
>
> Thanks,
> Jarvis
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
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/b0b0b57c-e152-4340-98ba-86933156a737%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-19 Thread tango ward
Thanks Xavier

On Mon, Feb 19, 2018 at 1:02 PM, Xavier Paniello  wrote:

> Hi tangoward15,
>
> Django will use auth.User as the user model in the system, unless you
> change AUTH_USER_MODEL = RegUser in settings.py
>
> Be carefull, to change the user model has some particularities you can
> read in docs (warning section):
> https://docs.djangoproject.com/en/2.0/ref/settings/#auth-user-model
>
> Other option to extend auth.User is a model with a one2one field related
> to auth.User, or a proxy model:
> https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-
> extend-django-user-model.html
>
> Salut!
>
>
> El diumenge, 18 febrer de 2018 15:23:53 UTC+1, tangoward15 va escriure:
>>
>> @Mukul Agrawal,
>>
>> thanks, i'll read this.
>>
>>
>> @Xavier,
>>
>> the model in forms.py, does it mean it will use the RegUser class from
>> the models.py? Sorry, I am confuse.
>>
>> On Sun, Feb 18, 2018 at 9:41 PM, Mukul Agrawal  wrote:
>>
>>> The answer on this link can also help you in why and when to use
>>> get_user_model().
>>> https://stackoverflow.com/questions/24629705/django-using-
>>> get-user-model-vs-settings-auth-user-model
>>>
>>>
>>> On Feb 18, 2018 4:11 AM, "tango ward"  wrote:
>>>
>>>
>>> Hi,
>>>
>>> I am playing around with user registration. I came across a code where
>>> the get_user_model() was assigned to a model in Meta class inside a form. I
>>> was just wondering, what is the benefit of using the get_user_model() as
>>> Model in a form instead of importing a class from models.py then use that
>>> class as model of the form and when should I use it?
>>>
>>> models.py
>>> class RegUser(User):
>>>
>>> def __str__(self):
>>> return self.username
>>>
>>> forms.py
>>>
>>> class UserCreateForm(UserCreationForm):
>>>
>>> class Meta:
>>> fields = ('username', 'password1', 'password2')
>>> model = get_user_model()
>>>
>>>
>>> Thanks,
>>> Jarvis
>>>
>>> --
>>> 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 post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R4
>>> 6BCuTN0xoA%40mail.gmail.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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF
>>> 7v3mXb3%3DP8D%2BA%40mail.gmail.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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> 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/226fceca-eb59-49c8-9606-b869f0c25feb%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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CAA6wQLKZoFWbg_67wtA%3DhFpPKu8OKo%3DCWZw-Baq6Wf%3D%2BZoNXcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread Xavier Paniello
Hi tangoward15,

Django will use auth.User as the user model in the system, unless you 
change AUTH_USER_MODEL = RegUser in settings.py

Be carefull, to change the user model has some particularities you can read 
in docs (warning section):
https://docs.djangoproject.com/en/2.0/ref/settings/#auth-user-model

Other option to extend auth.User is a model with a one2one field related to 
auth.User, or a proxy model:
https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html

Salut!


El diumenge, 18 febrer de 2018 15:23:53 UTC+1, tangoward15 va escriure:
>
> @Mukul Agrawal,
>
> thanks, i'll read this.
>
>
> @Xavier,
>
> the model in forms.py, does it mean it will use the RegUser class from the 
> models.py? Sorry, I am confuse.
>
> On Sun, Feb 18, 2018 at 9:41 PM, Mukul Agrawal  > wrote:
>
>> The answer on this link can also help you in why and when to use 
>> get_user_model(). 
>>
>> https://stackoverflow.com/questions/24629705/django-using-get-user-model-vs-settings-auth-user-model
>>
>>
>> On Feb 18, 2018 4:11 AM, "tango ward" > 
>> wrote:
>>
>>
>> Hi, 
>>
>> I am playing around with user registration. I came across a code where 
>> the get_user_model() was assigned to a model in Meta class inside a form. I 
>> was just wondering, what is the benefit of using the get_user_model() as 
>> Model in a form instead of importing a class from models.py then use that 
>> class as model of the form and when should I use it?
>>
>> models.py
>> class RegUser(User):
>>
>> def __str__(self):
>> return self.username
>>
>> forms.py
>>
>> class UserCreateForm(UserCreationForm):
>>
>> class Meta:
>> fields = ('username', 'password1', 'password2')
>> model = get_user_model()
>>
>>
>> Thanks,
>> Jarvis
>>
>> -- 
>> 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 post to this group, send email to django...@googlegroups.com 
>> .
>> 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/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R46BCuTN0xoA%40mail.gmail.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 django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> 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/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mXb3%3DP8D%2BA%40mail.gmail.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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/226fceca-eb59-49c8-9606-b869f0c25feb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread tango ward
@Mukul Agrawal,

thanks, i'll read this.


@Xavier,

the model in forms.py, does it mean it will use the RegUser class from the
models.py? Sorry, I am confuse.

On Sun, Feb 18, 2018 at 9:41 PM, Mukul Agrawal  wrote:

> The answer on this link can also help you in why and when to use
> get_user_model().
> https://stackoverflow.com/questions/24629705/django-
> using-get-user-model-vs-settings-auth-user-model
>
>
> On Feb 18, 2018 4:11 AM, "tango ward"  wrote:
>
>
> Hi,
>
> I am playing around with user registration. I came across a code where the
> get_user_model() was assigned to a model in Meta class inside a form. I was
> just wondering, what is the benefit of using the get_user_model() as Model
> in a form instead of importing a class from models.py then use that class
> as model of the form and when should I use it?
>
> models.py
> class RegUser(User):
>
> def __str__(self):
> return self.username
>
> forms.py
>
> class UserCreateForm(UserCreationForm):
>
> class Meta:
> fields = ('username', 'password1', 'password2')
> model = get_user_model()
>
>
> Thanks,
> Jarvis
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZXBF3R4
> 6BCuTN0xoA%40mail.gmail.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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> 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/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mX
> b3%3DP8D%2BA%40mail.gmail.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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CAA6wQLJDaCw30Rm05pEGOhpUJJt9yGSJ9R7FdnnNopANobY%2B7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread Mukul Agrawal
The answer on this link can also help you in why and when to use
get_user_model().
https://stackoverflow.com/questions/24629705/django-using-get-user-model-vs-settings-auth-user-model


On Feb 18, 2018 4:11 AM, "tango ward"  wrote:


Hi,

I am playing around with user registration. I came across a code where the
get_user_model() was assigned to a model in Meta class inside a form. I was
just wondering, what is the benefit of using the get_user_model() as Model
in a form instead of importing a class from models.py then use that class
as model of the form and when should I use it?

models.py
class RegUser(User):

def __str__(self):
return self.username

forms.py

class UserCreateForm(UserCreationForm):

class Meta:
fields = ('username', 'password1', 'password2')
model = get_user_model()


Thanks,
Jarvis

-- 
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 post to this group, send email to django-users@googlegroups.com.
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/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZX
BF3R46BCuTN0xoA%40mail.gmail.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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mXb3%3DP8D%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread Xavier Paniello
Hi tangoward15,

The User model by default is auth.User, but you can define a custom one and 
reference it at settings: 
https://docs.djangoproject.com/en/2.0/ref/settings/#auth-user-model

So, get_user_model() will return the model defined at AUTH_USER_MODEL 
setting.

Salut!

El dissabte, 17 febrer de 2018 23:44:34 UTC+1, tangoward15 va escriure:
>
> I also checked the documentation of it but I am confuse. It says "Instead 
> of referring to User 
> 
>  
> directly, you should reference the user model using 
> django.contrib.auth.get_user_model(). This method will return the 
> currently active user model – the custom user model if one is specified, or 
> User 
> 
>  
> otherwise." When it says "currently active user mode" is it the model that 
> I created in models.py or the one that is currently logged in to the 
> website? what does "or User otherwise" mean? 
>
> My apologies for asking too many questions.
>
> On Sun, Feb 18, 2018 at 6:39 AM, tango ward  > wrote:
>
>>
>> Hi, 
>>
>> I am playing around with user registration. I came across a code where 
>> the get_user_model() was assigned to a model in Meta class inside a form. I 
>> was just wondering, what is the benefit of using the get_user_model() as 
>> Model in a form instead of importing a class from models.py then use that 
>> class as model of the form and when should I use it?
>>
>> models.py
>> class RegUser(User):
>>
>> def __str__(self):
>> return self.username
>>
>> forms.py
>>
>> class UserCreateForm(UserCreationForm):
>>
>> class Meta:
>> fields = ('username', 'password1', 'password2')
>> model = get_user_model()
>>
>>
>> Thanks,
>> Jarvis
>>
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
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/00ed285c-9adf-4814-8626-6b856baee8a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-17 Thread tango ward
I also checked the documentation of it but I am confuse. It says "Instead
of referring to User

directly, you should reference the user model using
django.contrib.auth.get_user_model(). This method will return the currently
active user model – the custom user model if one is specified, or User

otherwise." When it says "currently active user mode" is it the model that
I created in models.py or the one that is currently logged in to the
website? what does "or User otherwise" mean?

My apologies for asking too many questions.

On Sun, Feb 18, 2018 at 6:39 AM, tango ward  wrote:

>
> Hi,
>
> I am playing around with user registration. I came across a code where the
> get_user_model() was assigned to a model in Meta class inside a form. I was
> just wondering, what is the benefit of using the get_user_model() as Model
> in a form instead of importing a class from models.py then use that class
> as model of the form and when should I use it?
>
> models.py
> class RegUser(User):
>
> def __str__(self):
> return self.username
>
> forms.py
>
> class UserCreateForm(UserCreationForm):
>
> class Meta:
> fields = ('username', 'password1', 'password2')
> model = get_user_model()
>
>
> Thanks,
> Jarvis
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
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/CAA6wQL%2BQuRBqAZpzeyszo719ruvo%3DO7jRPv2EkNAF6oEN6CMKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.