Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango : Adding a property to the User class. Changing it at runtime and UserManager.create_user
    primarykey
    data
    text
    <p>For various complicated reasons[1] I need to add extra properties to the Django User class.</p> <p>I can't use either Profile nor the "inheritance" way of doing this. (As in <a href="https://stackoverflow.com/questions/44109/extending-the-user-model-with-custom-fields-in-django">Extending the User model with custom fields in Django</a> )</p> <p>So what I've been doing is including the User class in my local_settings file. And adding the property to it there.</p> <p>This, perhaps surprisingly, seems to work in many cases. But not when I create a new User from UserManager.create_user(). So I need to patch an alternative to the UserManager.create_user() method. Looking at the source for this (in contrib.auth.models.py) I find that the class it uses to create the User is kept in a property called UserManager.model rather than referenced directly.</p> <p>The line is this : </p> <p>user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now)</p> <p>The problem is that this self.model (which I assume contains a reference to the User class) doesn't seem to be my patched version.</p> <p>So, does anyone know where this self.model is set-up in the case of UserManager? And whether I'm correct in assuming that at that point the code hasn't gone through local_settings so my patch to the User class isn't there? And if there's a better place to patch the class?</p> <p>cheers</p> <p>phil</p> <p>[1] To satisfy the cur ious. I need to make the User class use a different and existing table in the database, which has extra fields and constraints.</p> <p>Update : For future reference, it looks like Proxy Models are the way that Django's going to support what I need : <a href="http://code.djangoproject.com/ticket/10356" rel="nofollow noreferrer">http://code.djangoproject.com/ticket/10356</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload