PacktPublishing / Django-5-By-Example

Django 5 By Example (5th Edition) published by Packt
https://djangobyexample.com/
MIT License
244 stars 106 forks source link

Typo on page 220 - User used without importation #28

Open arbayong opened 2 months ago

arbayong commented 2 months ago

on page 220, both user and profile edit forms in their clean functions use the line User.objects...... but User has not been imported from django.contrib.auth

the UserRegistration form relies on the get_user_model() function to get the user model. thus User is not define.

i solved this by replacing User with get_user_model().objects.filter(....) each time. I'm sure when importing the get_user_model we can import it and give it an alias say UserModel. in that case the model attribute of the UserRegitration Form must point to this alias as using get_user_model() will throw and exception