On Sat, 2007-02-17 at 00:33 -0800, voltron wrote:
> Forgive if its so obvious, I have“nt coded in Python for a while.
> While poking around in the Django internals, I saw this:
>
> # snip
>
> class UserManager(models.Manager):
> def create_user(self, username, email, password):
> "Creates and saves a User with the given username, e-mail and
> password."
> now = datetime.datetime.now()
> user = self.model(None, username, '', '',
> email.strip().lower(), 'placeholder', False, True, False, now, now)
> ...
> ...
> #SNIP
>
> I do not understand this line:
> user = self.model(None, username, '', '', email.strip().lower(),
> 'placeholder', False, True, False, now, now)
In a model manager in Django (such as UserManager), the "model"
attribute refers to the model class that the current class is the
manager for. In this case, UserManager is a manager class for User,
which is lower down in the same file.
There is no immediately obvious way to trace from UserManager to User,
but fortunately things are named pretty sensibly and if you have a look
in the User class, you will see the line that says
objects = UserManager()
This sets up a custom model manager as described in
http://www.djangoproject.com/documentation/model_api/#managers
So calling self.model(...) instantiates an instance of the User class.
Django has a feature that the arguments to the class constructor are the
Django fields in the order they are specified. The fields in the User
class are username, first name, last name, email, password, etc, which
matches up with the paramters passed in above (no first- and last-names,
password == "placeholder" and so on).
Hope this clarifies things a little bit for you.
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---