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 > <https://docs.djangoproject.com/en/2.0/ref/contrib/auth/#django.contrib.auth.models.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 > <https://docs.djangoproject.com/en/2.0/ref/contrib/auth/#django.contrib.auth.models.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 <tango...@gmail.com > <javascript:>> 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.